Browse Source

获取微信JsSDK数据接口2

master
wanghongjun 1 year ago
parent
commit
dfd9522f19
  1. 9
      app/controller/wechat/Wechat.php
  2. 16
      app/service/wechat/WechatService.php

9
app/controller/wechat/Wechat.php

@ -130,11 +130,16 @@ class Wechat extends Base
}
}
public function getJsSdkData()
public function getJsSdkData(Request $request)
{
try {
$param = $request->param();
validate()->rule(['url' => 'require'])->check($param);
$url = urldecode($param['url']);
$WechatService = new WechatService();
return $this->buildSuccess($WechatService->getJsSdkSignature());
return $this->buildSuccess($WechatService->getJsSdkSignature($url));
} catch (\Exception $e) {
return $this->buildFailed(ReturnCode::INVALID,$e->getMessage());
}

16
app/service/wechat/WechatService.php

@ -71,27 +71,19 @@ class WechatService extends BaseService
/**
*
* @param $url
* @return array
* @throws FuncException
*/
public function getJsSdkSignature(): array
public function getJsSdkSignature($url): array
{
$timestamp = time();
$nonceStr = generate_random_string(16);
$nonceStr = generate_random_string(10);
$jsapi_ticket = $this->getJsApiTicket();
$ascllArr = [
'noncestr=' . $nonceStr,
'jsapi_ticket=' . $jsapi_ticket,
'timestamp=' . $timestamp,
'url=' . 'http://mp.weixin.qq.com?params=value',
];
sort($ascllArr);
$signature = sha1(implode('&', $ascllArr));
$signature = sha1(sprintf('jsapi_ticket=%s&noncestr=%s&timestamp=%s&url=%s', $jsapi_ticket, $nonceStr, $timestamp, $url));
return [
'appId' => env('wechat.appid'),

Loading…
Cancel
Save