From 0f9fbe46961eb09098943ec7f74faba2ef30a3c7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2023 14:32:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?edit=E6=B7=BB=E5=8A=A0jsapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/api/controllers/DefaultController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/api/controllers/DefaultController.php b/modules/api/controllers/DefaultController.php index e22b646..596959c 100644 --- a/modules/api/controllers/DefaultController.php +++ b/modules/api/controllers/DefaultController.php @@ -46,6 +46,7 @@ class DefaultController extends Controller 'api/default/debug', 'api/default/update-admin', 'api/default/disclaimer-info', + 'api/default/get-jssdk', ] ] ]); @@ -276,5 +277,11 @@ class DefaultController extends Controller ]); } + /** + * @ 获取js-sdk前端所需参数 + */ + public function actionGetJssdk(){ + return $this->responseHandler($this->wechat_mp->jsapi); + } } \ No newline at end of file From 6044f3b915c3c88642171825fc2938122a39eaad Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2023 14:36:37 +0800 Subject: [PATCH 2/3] edit --- modules/admin/models/Menu.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/admin/models/Menu.php b/modules/admin/models/Menu.php index 93d8357..6eb3899 100644 --- a/modules/admin/models/Menu.php +++ b/modules/admin/models/Menu.php @@ -535,18 +535,18 @@ class Menu 'is_show' => true, 'route' => 'admin/page/about-us', ], -// [ -// 'name' => '微信小程序', -// 'is_menu' => true, -// 'is_show' => true, -// 'route' => null, -// 'children' => [ -// [ -// 'name' => '微信配置', -// 'is_menu' => true, -// 'is_show' => true, -// 'route' => 'admin/wechat/mp', -// ], + [ + 'name' => '微信小程序', + 'is_menu' => true, + 'is_show' => true, + 'route' => null, + 'children' => [ + [ + 'name' => '微信配置', + 'is_menu' => true, + 'is_show' => true, + 'route' => 'admin/wechat/mp', + ], // [ // 'name' => '轮播图', // 'is_menu' => true, @@ -559,8 +559,8 @@ class Menu // 'is_show' => false, // 'route' => 'admin/wechat/mp-tpl-msg', // ], -// ] -// ], + ] + ], // [ // 'name' => '短信设置', // 'is_menu' => true, From ca9ffdc2c24b608af4164ba65fa7848d0ea433ab Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2023 15:46:13 +0800 Subject: [PATCH 3/3] =?UTF-8?q?edit=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/SiteController.php | 3 ++ modules/api/controllers/DefaultController.php | 6 +++- modules/api/models/WxmpAuthMobileForm.php | 34 ++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 1e86879..246759a 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -29,6 +29,9 @@ class SiteController extends Controller */ public function actionIndex() { + $code = $this->request->get('code'); + echo($code); + exit(); return $this->render('index'); } diff --git a/modules/api/controllers/DefaultController.php b/modules/api/controllers/DefaultController.php index 473a82f..4666de8 100644 --- a/modules/api/controllers/DefaultController.php +++ b/modules/api/controllers/DefaultController.php @@ -28,6 +28,7 @@ use app\modules\api\behaviors\LoginBehavior; use app\models\PageForm; use app\components\SiteHelper; use app\modules\api\components\ApiHelper; +use app\modules\api\models\WxmpAuthMobileForm; use Wechat\Wechat; class DefaultController extends Controller @@ -281,6 +282,9 @@ class DefaultController extends Controller * @ 获取js-sdk前端所需参数 */ public function actionGetJssdk(){ - return $this->responseHandler($this->wechat_mp->jsapi); + $obj = new WxmpAuthMobileForm(); + $obj->url = $this->request->get('url'); + $obj->wechat_mp = $this->wechat_mp; + return $this->responseHandler($obj->actionGetJssdk()); } } \ No newline at end of file diff --git a/modules/api/models/WxmpAuthMobileForm.php b/modules/api/models/WxmpAuthMobileForm.php index 3c699ee..f0efa83 100644 --- a/modules/api/models/WxmpAuthMobileForm.php +++ b/modules/api/models/WxmpAuthMobileForm.php @@ -32,6 +32,7 @@ class WxmpAuthMobileForm extends ApiModel public $wechat_mp; public $cx_mch_id; + public $url; public function rules() @@ -120,6 +121,37 @@ class WxmpAuthMobileForm extends ApiModel 'msg' => 'ok', 'data' => $res ]; - } + } + + /** + * @ 获取js-sdk前端所需参数 + */ + public function actionGetJssdk(){ + $redis_name = "api:{$this->wechat_mp->appId}:actionGetJssdk_1"; + $get = \Yii::$app->redis->get($redis_name); + if(empty($get)){ + $accessToken = $this->wechat_mp->getAccessToken(); + // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; + $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=".$accessToken; + $this->wechat_mp->curl->get($url); + $res = json_decode($this->wechat_mp->curl->response); + $get = $res->ticket; + \Yii::$app->redis->setex($redis_name,6800,$get); + } + $uniq = uniqid(); + $time = time(); + $str = "jsapi_ticket={$get}&noncestr={$uniq}×tamp={$time}&url={$this->url}"; + $sign = sha1($str); + $return = [ + 'appId' => $this->wechat_mp->appId, + 'timestamp' => $time, + 'nonceStr' => $uniq, + 'signature' => $sign, + 'jsApiList' => [ + 'scanQRCode', + ], + ]; + return $this->apiReturnSuccess('ok',$return); + } }