Commit c309c16b authored by 王峰's avatar 王峰

公众号分享签名

parent bf40fb7b
......@@ -55,9 +55,15 @@ class Company extends BaseController
*/
public function wxPackage()
{
$param = input();
if (!array_key_exists('url', $param) || empty($param['url'])) {
$url = 'https://wx.readerai.cn/';
}else{
$url = $param['url'];
}
include_once dirname(dirname(dirname(__DIR__))).'/extend/wxjs_sdk/jssdk.php';
$wx_sdk = new \JSSDK('wx46df32c2ccfc177d','cde9bf412f5a0e524c143241daf9a383');
$result = $wx_sdk->getSignPackage();
$result = $wx_sdk->getSignPackage($url);
return $this->returnJson($result);
}
......
......@@ -11,13 +11,12 @@ class JSSDK
$this->appSecret = $appSecret;
}
public function getSignPackage()
public function getSignPackage($url)
{
$jsapiTicket = $this->getJsApiTicket();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this->createNonceStr();
......@@ -53,7 +52,7 @@ class JSSDK
$accessToken = $this->getAccessToken();
// 如果是企业号用以下 URL 获取 ticket
// $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";
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken&type=jsapi";
$res = json_decode($this->httpGet($url));
$ticket = $res->ticket;
/*if ($ticket) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment