WeChat Custom share PHP code Analysis _php Instance

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.