您的位置:首页 > 移动开发 > 微信开发

微信生成二维码

2015-12-22 12:56 525 查看
本人小菜鸟一仅仅。为了自我学习和交流PHP(jquery,linux,lamp,shell,javascript,server)等一系列的知识,小菜鸟创建了一个群。希望光临本博客的人能够进来交流。寻求共同发展。

搭建平台。本人博客也有很多的技术文档。希望能够为你提供一些帮助。

QQ群: 191848169 QQ:450225664

//生成带參数的暂时二维码 用于绑定微信号

$memcache = new Memcache;
$memcache->addServer('127.0.0.1',11211);
//检測是否有反复
do{
$rand_code = rand(20000,30000);
}while($memcache->get($rand_code));
//将user_id 存入memcache 缓存
$memcache->set($rand_code,$_SESSION['user_id'],3600);

//获得access_token;
// $resultd =file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxdafc634908061c97&secret=584d57925a832e76676adeabb785dce8');
// $resultd = json_decode($resultd);
// $access_token = $resultd->access_token;
$access_token = WXBaseFun::getAccessToken();
//获得ticket
$qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": '.$rand_code.'}}}';
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$access_token";
$resulstd = https_post($url,$qrcode);
$jsoninfo = json_decode($resulstd,true);
$ticket = $jsoninfo['ticket'];
//下载二维码图片
$urls = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
$imageinfo = downloadimagefromweixin($urls);
$filename = time().'_qrcode.jpg';
$local_file = fopen('qrcode/'.$filename, 'w');
if(false !==$local_file){
if(false !==fwrite($local_file, $imageinfo['body'])){
fclose($local_file);
}
}
//分配生成的图片
$smarty->assign('code_img',$filename);

//生成带參数的二维码结束
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: