PHP to realize WeChat share to friends and record share count function example detailed

Source: Internet
Author: User
This article mainly introduces the implementation of PHP to share to the circle of friends and record share of the function, combined with an example of the PHP sharing function interface call and share count statistics specific operation skills, the need for friends can refer to the next

This article describes the PHP implementation of the share to the circle of friends and record share count function. Share to everyone for your reference, as follows:

1. Introduction of JS File
2. Inject permission verification configuration via Config interface
3. Successful validation through the Ready interface
4. Handling failure verification via the error interface

JSDK file Description:https://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html

(1)


<script type= "Text/javascript" src= "Http://res.wx.qq.com/open/js/jweixin-1.0.0.js" ></script>

(2) page join to get the value of Webconfig authentication information


<?php$url=dirname (DirName (DirName (DirName (dirname (dirname)))); $url = $url. ' /addons/lb_vote/jssdk.php '; include $url; $JSDK =new jssdk (' wxa3816b432f7291ba ', ' e469db86bec9661650362dc2f9df8956 ') ; $signPackage = $jsdk->getsignpackage ();? >

(3) Verify Config


Wx.config ({debug:false,appid: ' <?php echo $signPackage ["appId"];? > ',//required, the unique identity of the public number timestamp:<?php echo $signPackage ["timestamp"];? The timestamp noncestr: ' <?php echo $signPackage ["noncestr"];?. > ',//required, generate a random string of signatures signature: ' <?php echo $signPackage ["signature"];? > ',//required, signature, see Appendix 1jsApiList: [' Checkjsapi ', ' onmenusharetimeline ']//});

(4) Share to Friends Circle interface


Wx.ready (function () {   wx.onmenusharetimeline ({  title: ' Test sharing Friends circle '),//share title  link: "{php echo '/http '. $_ server[' http_host '].$_server[' Request_uri '];} ",//Share link  imgurl: ' {php echo $_w[' Siteroot '];} {$photo} ',//share icon  success:function () {//the    number of times the user confirms the share of the callback function executed after sharing   $.ajax ({      URL: "{php echo $this Createmobileurl (' Index ', Array (' op ' = ' share ')} ',      type: ' Post ',      data: ' id= ' +{$userinfo [' id ']}+ ' & Rid= "+{$userinfo [' Rid ']},      dataType: ' json ',      success:function (data) {       if (data.flags==1) {        alert (data.msg);       } else if (data.flags==2) {        alert (data.msg);        location.href= "{php echo $this->createmobileurl (' Index ', Array (' op ' = ' Display ', ' id ' = $id)}" rel= " External nofollow ";       }}}     );  },  cancel:function () {    //The callback function executed after the user has canceled    alert (' Cancel sharing success! ');  }   );

(5) function to execute when validating errors


Wx.error (function (res) {   alert (res);});

(6) PHP side update database, record share count return processing information to the user

if ($op = = ' share ') {  $voteinfo =pdo_fetch ("Select *from". TableName (' Lb_vote_info '). " WHERE RID =: RID and Id=:id and uniacid=:uniacid and pass=:p ", Array (': rid ' = ' $_gpc[' rid '), ': Uniacid ' =>$_w[' Unia Cid '], ':p the =>1, ' id ' =>$_gpc[' id ')); $sharenum =intval ($voteinfo [' Sharenum ']) +1; $data =array (' sharenum ' = $sharenum,); $res =pdo_update (' Lb_vote_info ', $data, array (' ID ' =>$_gpc[' id '), ' Uniacid ' =>$_w[' uniacid '], ' rid ' =>$_gpc[' rid ')), if (!empty ($res)) {   $msg [' msg ']= ' has been shared to the circle of friends! ';   $msg [' Flags ']=2;   echo Json_encode ($msg);} else{  $msg [' msg ']= ' sharing failed! ';  $msg [' Flags ']=1;   echo Json_encode ($msg);}}
Related Article

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.