标签:str encode turn tran bin pat object mic etop
<?php
getwxacode();
//生成二维码
function getwxacode(){
$url = "https://api.weixin.qq.com/wxa/getwxacode?";
$url .= "access_token=" . getToken();
$postdata = [
"path" => "pages/index/index?clientId=3",
"width" => 430,
];
$res = curl_post($url,json_encode($postdata),$options=array());
$img = ‘./img/‘.time().‘.jpg‘;
$r = file_put_contents($img,$res);
echo "<img src=‘".$img."‘>";
}
//发送获取token请求,获取token(2小时)
function getToken() {
$url = getTokenUrlStr();
$res = curl_post($url,$postdata=‘‘,$options=array());
$data = json_decode($res,JSON_FORCE_OBJECT);
return $data[‘access_token‘];
}
//获取token的url参数拼接
function getTokenUrlStr()
{
$getTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?"; //获取token的url
$WXappid = "wx0399845015067c51"; //APPID
$WXsecret = "7d7205f85b79805006ecfa2121ef4272"; //secret
$str = $getTokenUrl;
$str .= "grant_type=client_credential&";
$str .= "appid=" . $WXappid . "&";
$str .= "secret=" . $WXsecret;
return $str;
}
function curl_post($url=‘‘,$postdata=‘‘,$options=array()){
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if(!empty($options)){
curl_setopt_array($ch, $options);
}
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
function curl_get($url=‘‘,$options=array()){
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TIMEOUT,5);
if(!empty($options)){
curl_setopt_array($ch,$options);
}
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
标签:str encode turn tran bin pat object mic etop
原文地址:https://www.cnblogs.com/cqlb/p/9561376.html