1. 程式人生 > 其它 >PHP生成小程式太陽碼

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; }