public function qrcode(){
global $_W;
global $_GPC;
$uid = intval($_GPC['uid']);
$member = pdo_get("ewei_shop_member",array('id'=>$uid));
if(!empty($member['qrcode'])){
return app_json(array('status'=>200,'url'=>$_W['siteroot'].$member['qrcode']));
}
$data_file = IA_ROOT.'/attachment/images/ziliao/'.date("Y").'/'.date('m');
//转码,把utf-8转成gb2312,返回转换后的字符串, 或者在失败时返回 FALSE。
$filename =iconv("UTF-8","gb2312",$data_file);
//检查文件或目录是否存在
if(!file_exists($filename)){
$newsfile = mkdir($filename,0777,true);
if($newsfile){
$filename=$data_file;
}
}else{
$filename=$filename;
}
$name = $this->random(8);
$save_url = 'attachment/images/ziliao/'.date("Y").'/'.date('m').'/'.$name.'.png';
//当前用户上级id
//$agentid = intval($_GPC['agentid']);
$url_a ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&secret=";
$access_token = file_get_contents($url_a);
$ac = json_decode($access_token,1);
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$ac['access_token'];
$data = [
"page"=>"pages/recruit/recruit",
"scene"=>$uid,
];
$post_data= json_encode($data,true);
$qrcode = $this->api_notice_increment($url,$post_data);
$errcode = json_decode($qrcode,true)['errcode'];
$errmsg = json_decode($qrcode,true)['errmsg'];
//成功的 code 为0
if($errcode) { // 存在即为不成功
//return app_json(array('msg'=>$errcode.":".$errmsg));
return app_json(array('msg'=>"生成二维码失败1"));
}
$jpg = $qrcode;//得到post过来的二进制原始数据
if(empty($jpg))
{
echo 'nostream';
exit();
}
$file = fopen($data_file.'/'.$name.'.png',"w");//打开文件准备写入
fwrite($file,$jpg);//写入
fclose($file);//关闭
$filePath = $data_file.'/'.$name.'.png';
//$res = file_put_contents($save_url,$qrcode);//将微信返回的图片数据流写入文件
if(!file_exists($filePath)){
return app_json(array('msg'=>"生成二维码失败"));
}else{
pdo_update('ewei_shop_member',array('qrcode'=>$save_url),array('id'=>$uid));
return app_json(array('status'=>200,'url'=>$_W['siteroot'].$save_url));
}
}
function api_notice_increment($url,$data)
{
$curl = curl_init();
$a = strlen($data);
$header = array("Content-Type: application/json; charset=utf-8","Content-Length: $a");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
小程序端 获取 scene
const scene= decodeURIComponent(options.scene);