微信开发-生成带参数的二维码及简单使用
2018-02-09 11:48
736 查看
// 配置微信
function getWechatAccessToken(){ $appid = appid; $appsecret = appsecret; $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret; //获取access_token $srt = $this->curl('POST',$url); $strjson=json_decode($srt); return $token = $strjson->access_token; }
// 获取access_token
function getWechatAccessToken(){ $appid = appid; $appsecret = appsecret; $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret; //获取access_token $srt = $this->curl('POST',$url); $strjson=json_decode($srt); return $token = $strjson->access_token; }
// 获取ticket 生成带参数的二维码 public function postTicket($id) { $accessToken = $this->getWechatAccessToken(); $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$accessToken;
//临时二维码 // $post_data = [ // "expire_seconds" => 604800, //时间为7天 此处是60*60*24*7 // "action_name" => "QR_SCENE", // "action_info" => [ // "scene" => [ // "scene_id" => $id, // ] // ] // ];
$post_data = [ "action_name" => "QR_LIMIT_SCENE", "action_info" => [ "scene" => [ "scene_id" => $id, ] ] ]; $dat = json_encode($post_data); $str = json_decode($this->curl('POST',$url,$dat)); // $ticket = $str->ticket; // return response()->json(['code'=>'200','msg'=>'ok','data'=>$ticket]); return response()->json(['code'=>200,'msg'=>'ok','data'=>$str]); }
// 根据ticket 生成二维码地址https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET// 使用带参数的二维码
$postStr = file_get_contents("php://input"); // 获取微信在回调地址传回来的数据 \Log::info(json_encode($postStr)); // 打印log日志 $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); // 把xml格式转换成字符串 $fromUsername = (string)$postObj->FromUserName; // 发送方帐号(一个OpenID) 扫码者openId $event = (string)$postObj->Event; // 获取类型 $EventKey = trim((string)$postObj->EventKey); // 事件KEY值 // $data = User::where('openId',$fromUsername)->first(); if ($event == 'subscribe' || $event == 'SCAN'){ if (!empty($EventKey)){ if (starts_with($EventKey,'qrscene_')){ $EventKey = substr($EventKey,8);// 截取 } $fatherId = User::where('openId',$EventKey)->first(); $a = User::where('scope', '=', 'user')->get()->max('id'); if (empty($a)) { $b = "QXZ00001"; } else { $bb = User::where('id', $a)->first()->invitation; $b = ++$bb; } $user = new User(); $user->father_id = $fatherId->id; // 父级id $user->scope = 'user'; $user->type = 'fans'; //用户类型 $user->invitation = $b; // 随机的邀请码 // 随机的邀请码 $user->openId = $fromUsername; if ($user->save()) { return response()->json(['code' => 200, 'msg' => '注册成功']); } else { return response()->json(['code' => 500, 'msg' => '注册失败']); } } }
相关文章推荐
- Java 微信开发(四)生成带参数二维码及分享到朋友圈、好友、QQ
- C#微信开发之旅(六):生成带参数的二维码
- 微信开发——带参数二维码的使用
- 微信开发——带参数二维码的使用
- 微信开发——带参数二维码的使用
- 微信开发生成带参数的二维码的讲解
- 微信开发之——Php批量生成带参数的二维码
- php微信开发之批量生成带参数的二维码
- php微信开发之带参数二维码的使用
- 基于OpenJWeb平台的微信服务号开发培训-生成带参数二维码
- 微信开发之-Php批量生成带参数的二维码
- 微信 开发生成带参数的二维码的实例
- 微信带场景参数的二维码生成与使用
- php微信开发之带参数二维码的使用
- php微信开发之批量生成带参数的二维码
- 微信接口开发之高级篇系列【用户分组接口和生成带参数的二维码】
- 微信 开发生成带参数的二维码的实例
- 微信开发6----------生成带参数的二维码
- 微信公共服务平台开发(.Net)-生成带参数的二维码
- php微信开发之带参数二维码的使用