| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\Option;
- use yii\db\Exception;
- use yii\helpers\Json;
- use app\constants\OptionSetting;
- class AlipayConfigController extends BaseController
- {
- /**
- * 支付宝配置
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isPost) {
- $appId = trim(post_params('app_id'));
- $alipay_public_key = trim(post_params('alipay_public_key'));
- $app_public_key = trim(post_params('app_public_key'));
- $app_private_key = trim(post_params('app_private_key'));
- $aes_key = trim(post_params('aes_key'));
- $user_id = trim(post_params('user_id'));
- $name = trim(post_params('name'));
- if (empty($appId) || empty($alipay_public_key) || empty($app_public_key)
- || empty($app_private_key) || empty($aes_key) || empty($user_id) || empty($name)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请完善必填信息再进行提交修改!'
- ]);
- }
- $data['aes_key'] = $aes_key;
- $data['app_id'] = $appId;
- $data['alipay_public_key'] = $alipay_public_key;
- $data['app_public_key'] = $app_public_key;
- $data['app_private_key'] = $app_private_key;
- $data['user_id'] = $user_id;
- $data['name'] = $name;
- if (Option::set(Option::OPTOPN_KEY, Json::encode($data), get_store_id(), 'alipay')) {
- \Yii::$app->cache->delete('alipay_config_cache_' . get_store_id());
- \Yii::$app->cache->set('alipay_config_cache_' . get_store_id(), Json::encode($data));
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- }
- if(\Yii::$app->isSaas()){
- $config_cache = \Yii::$app->cache->get('alipay_config_cache_business_' . get_store_id());
- }else{
- $config_cache = \Yii::$app->cache->get('alipay_config_cache_' . get_store_id());
- }
- if ($config_cache) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => Json::decode($config_cache)
- ]);
- }
- $value = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay');
- if(\Yii::$app->isSaas()){
- $b_value = Json::decode($value['value'],true);
- unset($b_value['aes_key']);
- unset($b_value['alipay_public_key']);
- unset($b_value['app_public_key']);
- unset($b_value['app_private_key']);
- $b_value['is_saas'] = 1;
- $value['value'] = json_encode($b_value);
- \Yii::$app->cache->set('alipay_config_cache_business_' . get_store_id(), $value['value']);
- }else{
- \Yii::$app->cache->set('alipay_config_cache_' . get_store_id(), $value['value']);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => Json::decode($value['value'])
- ]);
- }
- /**
- * 支付宝配置
- */
- public function actionCrtIndex()
- {
- $dandianpuh5 = \Yii::$app->prod_is_dandianpu();
- $is_dandianpuh5 = intval(input_params('dandianpuh5'));
- $key = $dandianpuh5 && $is_dandianpuh5 ? OptionSetting::ALIPAY_PAY_DANDIANPUH5 : Option::ALIPAY_CONFIG_CERT;
- if (\Yii::$app->request->isPost) {
- $app_id = trim(post_params('app_id'));
- $alipay_public_cert = trim(post_params('alipay_public_cert'));
- $app_public_cert = trim(post_params('app_public_cert'));
- $alipay_root_cert = trim(post_params('alipay_root_cert'));
- $app_private_key = trim(post_params('app_private_key'));
- /*if (empty($app_id) || empty($alipay_public_cert) || empty($app_public_cert) || empty($alipay_root_cert)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请完善必填信息再进行提交修改!'
- ]);
- }*/
- $data['app_id'] = $app_id;
- $data['alipay_public_cert'] = $alipay_public_cert;
- $data['app_public_cert'] = $app_public_cert;
- $data['alipay_root_cert'] = $alipay_root_cert;
- $data['app_private_key'] = $app_private_key;
- try {
- Option::set($key, Json::encode($data), get_store_id(), 'alipay');
- } catch (Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- }
- $value = Option::get($key, get_store_id(), 'alipay');
- if (!empty($value)) {
- $data = Json::decode($value['value']);
- }
- if (empty($data)) {
- $data = [
- 'app_id' => '',
- 'alipay_public_cert' => '',
- 'app_public_cert' => '',
- 'alipay_root_cert' => '',
- 'app_private_key' => ''
- ];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => $data
- ]);
- }
- }
|