The previous paragraph to do custom sharing, accumulated some experience, share to everyone.
Step one or two is already detailed in the developer documentation, just start with step three.
step three parameters to parameters, in addition to AppID, the other parameters are dynamic, here, I use the PHP language, the parameters generated in the backend, the code is as follows:
PHP-Side code:
Public Function Getwxinfo () { $dataurl = I (' Dataurl '); Include ('./thinkphp/library/vendor/jssdk/jssdk.php '); $JSSDK = new \jssdk (' appId ', ' Appsecret '); $signPackage = $jssdk->getsignpackage ($dataurl);
When generating the signature, you must get the URL of the current page, so $dataurl is obtained through the following JS dynamic, remember.
JS Terminal code:
var dataurl = window.location.href; $.ajax ({type: ' post ', data:{' Dataurl ':d ataurl}, url: '/index.php/home/index/getwxinfo ', DataType: ' JSON ', success: function (JSON) {var list = Json.data; var appId = list.appid; var timestamp = List.timestamp; var noncestr = list.noncestr; var signature = List.signature; Weixininfo (appid,timestamp,noncestr,signature); }, Error:function () {//alert (' Network not giving force oh ... ')}); function Weixininfo (appid,timestamp,noncestr,signature) {wx.config ({debug:false, appid:appid, Timestamp:timestam P, Noncestr:noncestr, Signature:signature, jsapilist: [' Checkjsapi ',//determine if the current client version supports the specified JS interface ' Onmenusharetimel Ine ',//share to the circle of Friends ' onmenushareappmessage ',//share to Friends ' onmenushareqq ',//share to QQ ' Onmenushareweibo '//share to Weibo]}); } wx.ready (function () {///friend var s_title = ' share title '; var S_desc = ' share description '; var s_link = ' post-sharing link '; var s_imgurl = ' picture link '; Wx.onmenushareappmessage ({//For example, share the API Title:s_title with the Friends Circle//share title Desc:s_desc,//shareDescription Link:s_link,//Share link imgurl:s_imgurl,//Share icon Success:function () {}, Cancel:function () {}}); Friends Circle Wx.onmenusharetimeline ({title:s_title,//share title Link:s_link,//Share link imgurl:s_imgurl,//share icon Success:f Unction () {}, Cancel:function () {}}); QQ friend Wx.onmenushareqq ({title:s_title,//share title Desc:s_desc,//Share description link:s_link,//Share link imgurl:s_imgurl,/ /share icon Success:function () {}, Cancel:function () {}}); }); Wx.error (function (res) {
alert (res.errmsg); Print error message. And put Debug:false, set to Debug:ture can be directly on the page to see the error message pop-up
});
It's so simple.
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support the script home.