shouquan.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /*
  3. CopyRight 2014 All Rights Reserved
  4. */
  5. define("TOKEN", "eqcxcx");
  6. define("AppID", "wxd6972323f37bfdf0");//Appsecret
  7. define("Appsecret", "e7c30a645edec78aa64d30a92024237b");
  8. define("EncodingAESKey", "53o42sbbzslie4tjbll3ta5zlwe11rrk53o42sbbzsl");
  9. $ComponentVerifyTicket = file_get_contents('json/VerifyTicket.json');
  10. //echo "ComponentVerifyTicket=>". $ComponentVerifyTicket;
  11. //2、获取第三方平台component_access_token
  12. $token= getToken(AppID,Appsecret,$ComponentVerifyTicket,'11111');
  13. //echo "<br>";
  14. //echo "token=>".$token;
  15. //3获取预授权码pre_auth_code
  16. $data='{"component_appid":"'.AppID.'" }';
  17. $url="https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=".$token;
  18. $pre_auth_code=http_post_data($url,$data);
  19. //echo "<br>".$pre_auth_code;
  20. $pre_auth_code=json_decode($pre_auth_code,true)['pre_auth_code'];
  21. $redirect_url="http://web.woshangtong.com/addons/qidong_app/redirect_url.php";
  22. $openurl="https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=".AppID."&pre_auth_code=$pre_auth_code&redirect_uri=$redirect_url&auth_type=";
  23. //echo "<br>";
  24. //echo "pre_auth_code=>".$pre_auth_code;
  25. // echo "<br>";
  26. ?>
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  28. <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">
  29. <head>
  30. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  31. <title>在手机微信上做客服,30秒自主开通</title>
  32. <style type="text/css">
  33. .center
  34. {
  35. margin-left:auto;
  36. opacity:0.5;
  37. padding:10px; width:80px; height:80px;
  38. -moz-border-radius: 15px;
  39. -webkit-border-radius: 15px;
  40. border-radius:15px;
  41. }
  42. body
  43. {
  44. background-image: url('http://web.woshangtong.com/attachment/images/global/fh0HERD4p8mr8pEsMmM0Gb9hENm9M8.jpg');
  45. background-repeat: repeat-y;
  46. }
  47. .align-center{
  48. position:fixed;left:40%;top:30%;margin-left:width/2;margin-top:height/2;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="align-center">
  54. <table >
  55. <tr>
  56. <th>
  57. <img width='200' src='logo.png'>
  58. </th>
  59. </tr>
  60. <tr>
  61. <th>
  62. <br>
  63. </th>
  64. </tr>
  65. <tr>
  66. <th>
  67. <? if ($pre_auth_code<>''){?>
  68. <a href='<?php echo $openurl ;?>'><img src='https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon_button3_1.png'></a>
  69. <? }else{ echo "请刷新本页.";}?>
  70. </th>
  71. </tr>
  72. </table>
  73. </div>
  74. <div>
  75. <?echo zhucelist('jsonX/zhucelist.json');?>
  76. </div>
  77. </body>
  78. </html>
  79. <?php
  80. function http_post_data($url, $data_string) {
  81. $ch = curl_init();
  82. curl_setopt($ch, CURLOPT_POST, 1);
  83. curl_setopt($ch, CURLOPT_URL, $url);
  84. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  85. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  86. 'Content-Type: application/json; charset=utf-8',
  87. 'Content-Length: ' . strlen($data_string))
  88. );
  89. ob_start();
  90. curl_exec($ch);
  91. $return_content = ob_get_contents();
  92. //echo $return_content."<br>";
  93. ob_end_clean();
  94. $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  95. // return array($return_code, $return_content);
  96. return $return_content;
  97. }
  98. function getToken($appid,$appsecret,$ComponentVerifyTicket,$jsonid){
  99. $file = file_get_contents("jsonX/{$appid}_token.json",true);
  100. $result = json_decode($file,true);
  101. if (time() > $result['expires']){
  102. $data = array();
  103. $data['component_access_token'] = getNewToken($appid,$appsecret,$ComponentVerifyTicket);
  104. $data['expires']=time()+6200;
  105. $jsonStr = json_encode($data);
  106. $fp = fopen("jsonX/{$appid}_token.json", "w");
  107. fwrite($fp, $jsonStr);
  108. fclose($fp);
  109. return $data['component_access_token'];
  110. }else{
  111. return $result['component_access_token'];
  112. }
  113. }
  114. function getNewToken($appid,$appsecret,$ComponentVerifyTicket){
  115. $data_string='{
  116. "component_appid":"'.$appid.'" ,
  117. "component_appsecret": "'.$appsecret.'",
  118. "component_verify_ticket": "'.$ComponentVerifyTicket.'"
  119. }';
  120. $access_token_Arr =http_post_data("https://api.weixin.qq.com/cgi-bin/component/api_component_token", $data_string);
  121. //echo "<br>---";
  122. $access_token_Arr=json_decode($access_token_Arr,true);
  123. return $access_token_Arr['component_access_token'];
  124. }
  125. function zhucelist($path){
  126. $lines = file($path);
  127. $list='';
  128. $imglist='';
  129. foreach ($lines as $line) {
  130. $line = rtrim($line);
  131. $i++;
  132. $zhuce=json_decode($line, true);
  133. $list=$zhuce['name'].' '.$list;
  134. $imglist=' <img class="center" title="'.$zhuce['name'].'" src="'.$zhuce['head_img'].'"> '.$imglist;
  135. // more statements...
  136. }//如果没找到.
  137. return $imglist;
  138. }
  139. ?>