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); + } }