This commit is contained in:
尖叫 2023-10-27 16:06:33 +08:00
commit 8ed6873475
4 changed files with 339 additions and 294 deletions

View File

@ -29,6 +29,9 @@ class SiteController extends Controller
*/
public function actionIndex()
{
$code = $this->request->get('code');
echo($code);
exit();
return $this->render('index');
}

View File

@ -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,

View File

@ -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
@ -46,6 +47,7 @@ class DefaultController extends Controller
'api/default/debug',
'api/default/update-admin',
'api/default/disclaimer-info',
'api/default/get-jssdk',
]
]
]);
@ -276,5 +278,13 @@ class DefaultController extends Controller
]);
}
/**
* @ 获取js-sdk前端所需参数
*/
public function actionGetJssdk(){
$obj = new WxmpAuthMobileForm();
$obj->url = $this->request->get('url');
$obj->wechat_mp = $this->wechat_mp;
return $this->responseHandler($obj->actionGetJssdk());
}
}

View File

@ -32,6 +32,7 @@ class WxmpAuthMobileForm extends ApiModel
public $wechat_mp;
public $cx_mch_id;
public $url;
public function rules()
@ -121,5 +122,36 @@ class WxmpAuthMobileForm extends ApiModel
'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}&timestamp={$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);
}
}