码迷,mamicode.com
首页 > 微信 > 详细

微信获得场景二维码

时间:2015-05-07 13:55:28      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:

<?php
//获取access_token
require(‘init.php‘);
$s = $_GET[‘act_key‘];
preg_match(‘/\d+/‘,$s,$arr);//获取act_key里面的数字
$scene_id = (int)$arr[0]; //将数字转为int类型
//获取ticket
$qrcode = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": $scene_id}}}";
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$access_token";
$result = https_request($url,$qrcode);
$jsoninfo = json_decode($result, true);
$ticket = $jsoninfo["ticket"];

function https_request($url, $data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
//显示场景二维码
$codeurl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
header("location:$codeurl");
?>




微信获得场景二维码

标签:

原文地址:http://www.cnblogs.com/muxiaoye/p/dd97873152c32c5f48d6226709c9f24c.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!