首先每个活动生成不同的二维码
$hecode = $this->codes($insert_id);
$result = Db::table('')->where("activity_id='$insert_id'")->update(["cancel_code" => $hecode]);
codes的代码如下:
public function codes($goods_id)
{
$redirect_url = urlencode('http://' . $_SERVER['SERVER_N[**]ME'] . '/codes?goods_id=' . $goods_id);
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=" . $redirect_url . "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
$errorCorrectionLevel = 'H';//容错级别
$matrixPointSize = 3;//图片大小慢慢自己调整,只要是int就行
$path = 'uploads/qrcode/'; //上传位置
if (!file_exists($path)) {
mkdir($path);
}
$QR = $QRB = $path . rand(10000, 99999) . time() . ".png";
QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 2);
return $QR;
}
然后再跳转的页面进行判断
public function codes(){
$goods_id = $_REQUEST['goods_id'];
$code = $_REQUEST['code'];
$setting = Db::table('setting')->where('id = 1')->find();
$appid = $setting['appid'];
$secret = $setting['appsecret'];
$oauth2Url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code";
$oauth2 = $this->getJson($oauth2Url);
$openid = $oauth2['openid'];
$member = Db::table("")->where("openid = '$openid'")->find();
if($member){
$order = Db::table("order")
->where("member_id = ".$member['member_id'])
->select();
if($order){
$yes = Db::table("order")->where("order_id = ".$order[0]['order_id'])->update(['he_status'=>1,'he_time'=>time()]);
if($yes){
$aa = $this->alert('核销成功!','http://www.baidu.com',6,3);
echo $aa;
}else{
$aa = $this->alert('核销失败!','http://www.baidu.com',5,3);
echo $aa;
}
}else{
$aa = $this->alert('您没有要核销的订单,请先购买!','http://www.baidu.com',5,3);
echo $aa;
}
}else{
$aa = $this->alert('暂无您的购买信息,请先购买!','http://www.baidu.com',5,3);
echo $aa;
}
}
public function getJson($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, F[**]LSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, F[**]LSE);
curl_setopt($ch, CURLOPT_RETURNTR[**]NSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, true);
}
————————————————
版权声明:本文为CSDN博主「tian_fighting」的原创文章,遵循CC 4.0 BY-S[**]版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhangweiguangsunjiao/article/details/91581095