分享個php對接微信公衆號經常使用的代碼全集

如下是分享的代碼集合,直接修改token,並把代碼放到服務器對接微信的url的index.php下就能夠用使用了,簡單輕鬆。php

  1. <?php  api

  2. define("TOKEN", "weixin");  服務器

  3.    

  4. $wechatObj = new wechatCallbackapiTest();  微信

  5. //沒有獲得echostr 先驗證  ui

  6. if (!isset($_GET['echostr'])) {  this

  7.     $wechatObj->responseMsg();    //處理消息  url

  8. }else{  spa

  9.     $wechatObj->valid();  code

  10. }  token

  11. /*$code = $_GET["code"]; 

  12. $userinfo = getopenidtoken($code); 

  13. $StrOpenid=$userinfo["openid"]; 

  14. */  

  15. class wechatCallbackapiTest  

  16. {  

  17.     //驗證消息  

  18.     public function valid()  

  19.     {  

  20.         $echoStr = $_GET["echostr"];  

  21.         if($this->checkSignature()){  

  22.             echo $echoStr;  

  23.             exit;  

  24.         }  

  25.     }  

完整代碼能夠關注微信號,發送 ‘微信代碼’ 得到完整代碼:

輕輕關注,將推「心」的不錯經驗和知識,也有一些羣友的心得分享哦!

相關文章
相關標籤/搜索