欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

微信分享接口开发

1.微信分享接口的开发分几个步骤

a.得到ticket

b.根据ticket和url(#号后不要)得到signature,nonceStr,timestamp

c.根据得到的signature,nonceStr,timestamp 和appId 去通过config接口注入权限验证配置

d.通过ws.ready去实现分享接口,接口名称参考http://mp.weixin.qq.com/wiki/11/74ad127cc054f6b80759c40f77ec03db.html

官方校验签名网站:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign


示例如下:

a.引入(必要的)<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

· 可异步得到config接口需要的参数,开发的时候将这个改为true

[javascript] view plain copy
  1. debug : true  

[javascript] view plain copy
  1. <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>  

  2. <script type="text/javascript">  

  3.     var targetUrl = location.href.split("#")[0];  

  4.     $.ajax({  

  5.         url : "logonAction.do?proc=initWeiXin&targetUrl=" + targetUrl,  

  6.         type : "get",  

  7.         datatype : 'html',  

  8.         cache : true,  

  9.         success : function(html) {  

  10.             wx.config({  

  11.   

  12.                 debug : false,// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。  

  13.                 appId : eval('(' + html + ')').appId,// 必填,公众号的唯一标识  

  14.                 timestamp : eval('(' + html + ')').timestamp,// 必填,生成签名的时间戳  

  15.                 nonceStr : eval('(' + html + ')').nonceStr,// 必填,生成签名的随机串  

  16.                 signature : eval('(' + html + ')').signature,// 必填,签名,  

  17.                 jsApiList : [  

  18.                 // 所有要调用的 API 都要加到这个列表中  

  19.                 'onMenuShareTimeline' ]  

  20.             });  

  21.         }  

  22.     });



  23. <pre name="code" class="javascript"><span style="white-space:pre">   </span>

  24.    wx.ready(function() {  

  25.     //隐藏分享按钮  

  26.     //WeixinJSBridge.call('hideOptionMenu');  

  27.         wx.onMenuShareTimeline({  

  28.           title: '标题',  

  29.           link: 'https://www.baidu.com',  

  30.           imgUrl: 'https://www.baidu.com/img/bd_logo1.png',  

  31.           success: function () {   

  32.             alert('分享成功');  

  33.           },  

  34.           cancel: function () {   

  35.             alert('取消分享');  

  36.           }  

  37.           });   

  38.   

  39.     });</pre><br>  

  40. <pre></pre>  

  41. 分享结果如下  

  42. <p></p>  

  43. <p><span style="font-size:14px"><img src="" alt=""><br>  

  44. </span></p>  

  45. <p><span style="font-size:14px"><br>  

  46. </span></p>  

  47. <p><span style="font-size:14px"><br>  

  48. </span></p>  

  49. <p><span style="font-size:14px">注意:如果微信弹出 errormsg config invalid signature</span></p>  

  50. <p><span style="font-size:14px">,请确保</span><span style="font-size:14px; white-space:pre">url</span><span style="white-space:pre; color:rgb(51,51,51); font-family:Helvetica,Tahoma,Arial,sans-serif; line-height:24px; background-color:rgb(245,245,245)"><span style="font-size:14px">(#号后不要)的正确性,</span><strong><span style="font-size:18px">url和微信中复制链接地址是一样的</span></strong><span style="font-size:14px">(</span><span style="font-size:14px; color:rgb(51,51,51); font-family:Helvetica,Tahoma,Arial,sans-serif; line-height:24px; white-space:pre; background-color:rgb(245,245,245)">#号后不要</span><span style="font-size:14px">)</span></span></p>  

  51. <p><span style="font-size:14px"><br>  

  52. </span></p>  

  53. <p><span style="font-size:14px"><span style="white-space:pre"></span></span></p>  

  54.                       

文章标签: 微信微信公众号

来自  https://blog.csdn.net/qq_31307253/article/details/78675448

普通分类: