Home > Backend Development > PHP Tutorial > 微信 二维码生成接口 全是乱码什么问题

微信 二维码生成接口 全是乱码什么问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:12:50
Original
1831 people have browsed it

微信 二维码生成接口 全是乱码什么问题

<code><?php /*
 *获取微信token
*/
$appid="wx78478e595939c538";
$secret="5540e8ccab4f71dfad752f73cfb85780";
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";

//$token=(array)json_decode(file_get_contents($url));

$output=gettoken($url);

$token=(array)json_decode($output);

$token=$token['access_token'];
//print_r($token);
//echo $token['access_token'];
$date='{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 100}}}';
$erweimaurl="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$token."";
$erweimaarr=(array)json_decode(getshort($date,$erweimaurl));
//echo $erweimaarr['ticket'];

$huanurl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$erweimaarr['ticket']."";
echo gettoken($huanurl);

function gettoken($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
    curl_setopt($ch, CURLOPT_ENCODING ,'gzip'); //加入gzip解析
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

function getshort($data,$url){
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $tmpInfo = curl_exec($ch);
     if (curl_errno($ch)) {
      return curl_error($ch);
     }
     curl_close($ch);
     return $tmpInfo;
}
?></code>
Copy after login
Copy after login

微信 二维码生成接口 全是乱码什么问题

回复内容:

微信 二维码生成接口 全是乱码什么问题

<code><?php /*
 *获取微信token
*/
$appid="wx78478e595939c538";
$secret="5540e8ccab4f71dfad752f73cfb85780";
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";

//$token=(array)json_decode(file_get_contents($url));

$output=gettoken($url);

$token=(array)json_decode($output);

$token=$token['access_token'];
//print_r($token);
//echo $token['access_token'];
$date='{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 100}}}';
$erweimaurl="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$token."";
$erweimaarr=(array)json_decode(getshort($date,$erweimaurl));
//echo $erweimaarr['ticket'];

$huanurl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$erweimaarr['ticket']."";
echo gettoken($huanurl);

function gettoken($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
    curl_setopt($ch, CURLOPT_ENCODING ,'gzip'); //加入gzip解析
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

function getshort($data,$url){
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $tmpInfo = curl_exec($ch);
     if (curl_errno($ch)) {
      return curl_error($ch);
     }
     curl_close($ch);
     return $tmpInfo;
}
?></code>
Copy after login
Copy after login

微信 二维码生成接口 全是乱码什么问题

检查 页面输出的header 的 content-type 的类型

还有,提醒一下你这样暴露appid和secret真的好吗

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template