Wechat secondary sharing error, invalid signature

The h5 page based on WeChat public number (using jssdk interface) is shared by user A to user B. Users can not share this page when they share the pag...

The h5 page based on WeChat public number (using jssdk interface) is shared by user A to user B. Users can not share this page when they share the page again. The problem is that the sharing link received by user B is different from the one opened by user a
A user's link is

http://test.com/test.html

B connection received by user

http://test.com/test.html&from=singlemessage

from=singlemessage is the tag automatically added by wechat client to distinguish sharing source and link again,
When sharing again, we need to encode the automatically obtained connection in js code, and then process the url received in the background.

The sample code of js and php is as follows:
Pay attention to ajax, use post, use get. It's said that there is no escape (I didn't test the get method)

js code

function share(){ var nowurl = window.location.href; var nowurlo = nowurl.split('&')[0]; $.ajax({ type : "post", url : "***********************", //Back-end interface dataType : "json", data : { 'url': encodeURIComponent(nowurl) }, // Note that encode the nowurl here; success : function (data) { wx.config({ debug : false, //Debug mode appId : data.appId, //Public address appid timestamp : data.timestamp, //time stamp nonceStr : data.noncestr, //Generate a random string of signatures signature : data.signature, //autograph jsApiList : [ 'updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareAppMessage', 'onMenuShareTimeline', 'chooseWXPay', 'showOptionMenu', "hideMenuItems", "showMenuItems", "onMenuShareTimeline", 'onMenuShareAppMessage', ] // Required, list of JS interfaces to be used }); wx.ready(function () { //It needs to be called before the user may click the share button wx.updateAppMessageShareData({ title : '', // Share title desc : '', // Sharing description link : nowurlo, // Auto get (in the above js code) imgUrl : '', // Share Icon success : function () { } }); wx.updateTimelineShareData({ title : '', // Share title link : nowurlo, Auto get (above js Code) imgUrl : '', // Share Icon success : function () { }, }); }); } }); }

php code

public function generateSignature(){ $timestamp = time(); $jsapiTicket = ;//Get jsapi "ticket here $noncestr = md5(uniqid(microtime(true),true));//My noncestr $url = urldecode(I('post.url')); $signature = sha1('jsapi_ticket=' . $jsapiTicket . '&noncestr=' . $noncestr . '&timestamp=' . $timestamp . '&url=' . $url); $shareConfig['appId'] = '';//appId here $shareConfig['timestamp'] = $timestamp; $shareConfig['noncestr'] = $noncestr; $shareConfig['signature'] = $signature; $shareConfig['url'] = $url; echo json_encode($shareConfig); }

4 December 2019, 04:51 | Views: 2878

Add new comment

For adding a comment, please log in
or create account

0 comments