php 微信平台 无效的签名,微信公众平台, config:invalid signature一直爆这个错误,求教如何解决?...

解决了,如果测试签名和自己生成的签名一致的话,那就是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&timestamp=$timestamp&url=$url";

$signature = sha1($string);

$signPackage = array(

"appId" => $this->appId,

"nonceStr" => $nonceStr,

"timestamp" => $timestamp,

"url" => $url,

"signature" => $signature,

"rawString" => $string

);

return $signPackage;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值