欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信二次分享報(bào)錯(cuò)invalid signature問題及解決方法

 更新時(shí)間:2019年04月01日 14:15:00   作者:吳紅兵  
基于微信公眾號(hào)開發(fā)的h5頁面(使用jssdk接口),由用戶A分享給用戶B,用戶B再次分享這個(gè)頁面時(shí),不能成功分享。這篇文章主要介紹了微信二次分享報(bào)錯(cuò)invalid signature問題及解決方法,需要的朋友可以參考下

基于微信公眾號(hào)開發(fā)的h5頁面(使用jssdk接口),由用戶A分享給用戶B,用戶B再次分享這個(gè)頁面時(shí),不能成功分享。問題出在用戶B收到的分享鏈接與用戶A打開的鏈接不同

A用戶的鏈接為

http://test.com/test.html

B用戶收到的連接

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

from=singlemessage是微信客戶端為了區(qū)分分享來源再鏈接后自動(dòng)添加的標(biāo)記,再次分享時(shí),需要在js代碼中對(duì)自動(dòng)獲取的連接進(jìn)行encodeURIComponent處理,后臺(tái)再對(duì)收到的url進(jìn)行urldecode處理。

js與php示例代碼如下:

注意ajax,用的post,用get據(jù)說不用轉(zhuǎn)義(get方式本人未做測(cè)試)

js代碼

function share(){
  var nowurl     = window.location.href;
  var nowurlo   = nowurl.split('&')[0];
  $.ajax({
    type     : "post",
    url     : "***********************", //后端接口
    dataType   : "json",
    data     : { 'url': encodeURIComponent(nowurl) }, // 注意此處對(duì)nowurl進(jìn)行encode;
    success   : function (data) {
      wx.config({
            debug    : false,        //調(diào)試模式
            appId    : data.appId,      //公眾號(hào)appid
            timestamp  : data.timestamp,    //時(shí)間戳
            nonceStr   : data.noncestr,    //生成簽名的隨機(jī)串
            signature  : data.signature,    //簽名
            jsApiList  : [
              'updateAppMessageShareData',
              'updateTimelineShareData',
              'onMenuShareAppMessage',
              'onMenuShareTimeline',
              'chooseWXPay',
              'showOptionMenu',
              "hideMenuItems",
              "showMenuItems",
              "onMenuShareTimeline",
              'onMenuShareAppMessage',
          ] // 必填,需要使用的JS接口列表
      });
      wx.ready(function () {  //需在用戶可能點(diǎn)擊分享按鈕前就先調(diào)用
        wx.updateAppMessageShareData({ 
          title  : '', // 分享標(biāo)題
          desc   : '', // 分享描述
          link   : nowurlo, // 自動(dòng)獲取(上面js代碼中)
          imgUrl  : '', // 分享圖標(biāo)
          success : function () {
          }
        });
        wx.updateTimelineShareData({ 
          title   : '', // 分享標(biāo)題
          link   : nowurlo, 自動(dòng)獲?。ㄉ厦鎗s代碼中)
          imgUrl  : '', // 分享圖標(biāo)
          success  : function () {
          },
        });
      });
      
    }
  });
}

php代碼

 public function generateSignature(){
    $timestamp           = time();
    $jsapiTicket          = ;//此處獲取jsapi_ticket
    $noncestr           = md5(uniqid(microtime(true),true));//我用的noncestr
    $url              = urldecode(I('post.url'));
    $signature           = sha1('jsapi_ticket=' . $jsapiTicket . '&noncestr=' . $noncestr . '&timestamp=' . $timestamp . '&url=' . $url);
    $shareConfig['appId']     = '';//此處為appId
    $shareConfig['timestamp']   = $timestamp;
    $shareConfig['noncestr']    = $noncestr;
    $shareConfig['signature']   = $signature;
    $shareConfig['url']      = $url;
    echo json_encode($shareConfig);
  } 

總結(jié)

以上所述是小編給大家介紹的微信二次分享報(bào)錯(cuò)invalid signature問題及解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論