PHP生成小程序太陽碼


調用  get_xcs_qr_img($pdo,$scene)即可

function get_xcs_access_token($pdo){
    if(null ==SITE_ID){return false;}
    $token_path='f/'.SITE_ID.'/xcs_access.sql';
    if(is_file($token_path)){
        $r=file_get_contents($token_path);
        $r=json_decode($r,1);
        if($r['expires_in']>time()){return $r['access_token'];}
        
    }
    $c=get_config_data($pdo,'/payment/wxxcs/config.php');
    //var_dump($c);
    if($c['appid']=='' || $c['appsecret']==''){return false;}
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$c['appid']."&secret=".$c['appsecret'];
    $data = '{"name":sucaihuo}';
    $tokens= https_post($url,$data);
    $tokens = json_decode($tokens, true);
    $tokens['expires_in']=time()+$tokens['expires_in']-100;
    file_put_contents($token_path,json_encode($tokens));
    return  $tokens['access_token'];
}

function get_xcs_qr_img($pdo,$scene){
    $tokens=get_xcs_access_token($pdo);
    if(!$tokens){return '';}
    $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $tokens;
    $width = 100;
    $is_hyaline = 'true'; //
    $auto_color = 'false'; //默認值是false,自動配置線條顏色,如果顏色依然是黑色,則說明不建議配置主色調;
    $line_color = '{"r":"0","g":"0","b":"0"}'; //auth_color 為 false 時生效,使用 rgb 設置顏色 例如 {"r":"xxx","g":"xxx","b":"xxx"}
    $data = '{"scene":"' . $scene . '","width":' . $width . ',"auto_color":' . $auto_color . ',"line_color":' . $line_color . '}';
    $c = https_post($url, $data); 
    return $c;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM