Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

80 linhas
2.6 KiB

  1. <?php
  2. //调用
  3. require_once '../Common/Config.php';
  4. require_once '../Common/Function.php';
  5. if (!empty($_POST)){
  6. if( $_POST['media_id']=="" || $_POST['url']=="" ){
  7. echo "不能为空,填写真确的参数";
  8. exit;
  9. }
  10. $media_id=$_POST['media_id'];
  11. $Rurl=$_POST['url'];
  12. $sql="INSERT INTO qrcode(media_id,url,createtime) values('".$media_id."','".$Rurl."','".date("Y-m-d H:i:s")."')";
  13. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  14. $result=$pdo->exec($sql);
  15. $id= $pdo->lastInsertId();
  16. $dir="../Log";
  17. if (!is_dir($dir)){
  18. mkdir($dir);
  19. }
  20. $token_file=$dir.'/access_token';
  21. if (file_exists($token_file) && time()-filemtime($token_file)<4800){
  22. write_log("qrcode--文件中读取的token:".file_get_contents($token_file));
  23. $access_token= file_get_contents($token_file);
  24. }else{
  25. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;
  26. $result=http_request($url);
  27. if(!$result){
  28. write_log("qrcode-获取token出错");
  29. echo "qrcode-获取token出错";
  30. exit;
  31. }
  32. $result_obj=json_decode($result);
  33. file_put_contents($token_file, $result_obj->access_token);
  34. write_log("qrcode-url获取的token:".$result_obj->access_token);
  35. $access_token= $result_obj->access_token;
  36. }
  37. $qrcode='{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": '.$id.'}}}';
  38. $ticketUrl="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
  39. $resultTicket=http_request($ticketUrl,$qrcode);
  40. if ($resultTicket){
  41. write_log($resultTicket);
  42. $ticket_obj=json_decode($resultTicket);
  43. $ticket=$ticket_obj->ticket;
  44. write_log("qrcode.php-- $ticketUrl url获取ticket:".$ticket);
  45. }
  46. $qrcodeUrl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
  47. write_log("$qrcodeUrl".$qrcodeUrl);
  48. $imageInfo=downloadImageFromWeiXin($qrcodeUrl);
  49. $dir="./Images";
  50. if (!is_dir($dir)){
  51. mkdir($dir);
  52. }
  53. $filename=$dir."/qrcode"."-".$id."-".time().".jpg";
  54. $local_file=fopen($filename, 'w');
  55. if ($local_file !==false){
  56. if(fwrite($local_file, $imageInfo["body"]) !== false){
  57. fclose($local_file);
  58. /* $filePath=dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'])."/".$filename;
  59. downfile($filePath); */
  60. }
  61. }
  62. header("Location: $qrcodeUrl");
  63. exit;
  64. }
  65. ?>
  66. <html>
  67. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  68. <table>
  69. <tr><td align="right">media_id:</td><td><input type="text" name="media_id" value=""/></td></tr>
  70. <tr><td align="right">跳转url:</td><td><input type="text" name="url" value="" /></td></tr>
  71. </table>
  72. <input type="submit" value="提交" />
  73. </form>
  74. </html>