解决了,如果测试签名和自己生成的签名一致的话,那就是url的问题,可以通过js端生成url后用ajax或者get方式传到php端,具体为
function WeChat(url,title,shareimg){
$.get("{:U('Api/Test/action')}",{url:window.location.href},function(data) {
wx.config({
debug: true,
appId: data.appid,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: [
'wx.checkJsApi',
'wx.onMenuShareTimeline'
]
});
wx.ready(function() {
wx.checkJsApi({
jsApiList: ['chooseImage'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function(res) {
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
});
wx.onMenuShareTimeline({
title: title, // 分享标题
link: url, // 分享链接
imgUrl: shareimg, // 分享图标
success: function() {
// 用户确认分享后执行的回调函数
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
});
});},"json"
);
}
其中传过去的url地址为当前页面获取的url地址url:window.location.href
php端接收端:
Vendor('jssdk.jssdk');
$appid = 'wx4b87ea71b0972a8c';
$APPSECRET = 'd4c6a9ffb86d5afc9029d27fcc198680';
$url=$_GET["url"];
$jssdk = new JSSDK($appid, $APPSECRET,$url);
jssdk文件:传入url
class JSSDK {
private $appId;
private $appSecret;
private $url;
public function __construct($appId, $appSecret,$url) {
$this->appId = $appId;
$this->appSecret = $appSecret;
$this->url = $url;
}
public function getSignPackage() {
$jsapiTicket = $this->getJsApiTicket();
$url = $this->url;
$timestamp = time();
$nonceStr = $this->createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array(
"appId" => $this->appId,
"nonceStr" => $nonceStr,
"timestamp" => $timestamp,
"url" => $url,
"signature" => $signature,
"rawString" => $string
);
return $signPackage;
}
}