美文网首页
微信小程序生成太阳码

微信小程序生成太阳码

作者: Mracale | 来源:发表于2020-07-29 17:50 被阅读0次
<?php

/**
 * curl请求数据
 *
 * @param string $url 请求地址
 * @param array $param 请求参数
 * @param string $contentType 请求参数格式(json)
 * @return boolean|mixed
 */
function https_request($url = '', $param = [], $contentType = ''){
    $ch = curl_init();
    // 请求地址
    curl_setopt($ch, CURLOPT_URL, $url);
    // 请求参数类型
    $param = $contentType == 'json' ? json_encode($param) : $param;
    // 关闭https验证
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    // post提交
    if($param){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
    }
    // 返回的数据是否自动显示
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // 执行并接收响应结果
    $output = curl_exec($ch);
    // 关闭curl
    curl_close($ch);
    return $output !== false ? $output : false;
}
$appid = "";
$secret = "";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
// $res = file_get_contents($url);//获取token信息
// var_dump($res);die;
$access_token="";
$request_url='https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$access_token;
$request_data=array(
    'scene'=>'?cid=7',
    'page'=>'pages/index/index',
    'width'=>'690'
);
$result = https_request($request_url,$request_data,'json');
file_put_contents("7.jpg", $result);

相关文章

网友评论

      本文标题:微信小程序生成太阳码

      本文链接:https://www.haomeiwen.com/subject/wkrkrktx.html