获取小程序二维码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function getCode(){
    $post $this->input->post();
    $openid $post['openid'];
    $token = json_decode($this->get_token('wx725d23dc9ddc4223','8d5971b6282b271b23474849cb3ea562','client_credential'),true);
    $token_str $token['access_token'];
 
    $url "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$token_str";
    $data array("scene"=>"1001");
    $file_code $this->https_request($url, json_encode($data));
 
    $filename 'uploadfile/qrcode/'.$openid.'.png';
    file_put_contents($filename,$file_code);
 
    echo 'https://yj.chuanyinhulian.com/'.$filename;
}
 
function get_token($appid$secret$grant_type){
    $url "https://api.weixin.qq.com/cgi-bin/token?appid=$appid&secret=$secret&grant_type=$grant_type";
    return $this->https_request($url);
}
 
function https_request($url$data = null)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}