tp5生成小程序推广二维码
//获取用户经销商信息 及生成推广二维码
public function qrcode()
{
//拿到openid 查找用户表内是否有该用户 没有则拒绝生成二维码 有则查看是否已生成二维码 有生成则发送数据 没有则生成
$openid=input('post.openid');//得到用户openid
$dealer = Db::name("users")->where(['openid' => $openid])->value('tuiguangimg');
if($dealer==NULL){
if($dealer['qrcode'] == ''){
$appid = '';
$secret = '';//AppSecret(小程序密钥)
$url_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret;
$json_access_token = $this -> sendCmd($url_access_token,array());
$arr_access_token = json_decode($json_access_token,true);
$access_token = $arr_access_token['access_token'];
if(!empty($access_token)) {
$url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token='.$access_token;
$data = '{"path": "pages/my/my?uid='.$dealer.'", "width": 430}';
$result = $this -> sendCmd($url,$data);
$name = $openid.time();
file_put_contents('./upload/qrcode/code-'.$name.'.jpg',$result);
//存储二维码路径
$arr['tuiguangimg'] = '/upload/qrcode/code-'.$name.'.jpg';
$res=Db::name("users")->where(['openid' => $openid])->update($arr);
return GYReturn('1','暂无数据',$arr);
} else {
$arr = array('code'=>0,'msg'=>'ACCESS TOKEN为空!');
return GYReturn('1','暂无数据',$arr);
}
}else{
echo '获取二维码';
}
}else{
$arr['tuiguangimg'] = $dealer;
//echo "<img src=/youchis$dealer>";
return GYReturn('1','暂无数据',$arr);
}
} /**
* 发起请求
* @param string $url 请求地址
* @param string $data 请求数据包
* @return string 请求返回数据
*/
function sendCmd($url,$data)
{
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); //解决数据包大不能提交
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);
}
curl_close($curl); // 关键CURL会话
return $tmpInfo; // 返回数据
}
tp5生成小程序推广二维码的更多相关文章
- 关于微信小程序获取二维码的踩坑记录
1.踩坑需求:获取小程序的二维码 2.踩坑接口: https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN3 踩坑代码 pu ...
- 微信小程序获取二维码(直接上代码)https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN
应为是直接返回二进制数据所有与其他接口些许差别,希望能帮助现在的你! 谢谢!!! /** * 37.微信二维码生成 */ public String getWeiXinCourseMap() { ...
- 微信小程序--扫描二维码
场景---在微信中扫描朋友发来的二维码后进入小程序,其实那个地址是带有参数的,那么如何接收那个参数呢,其实就是进入小程序页面的onLoad生命周期行数的options参数里面.
- 又是新动作!微信小程序专属二维码出炉
又到了晚上,微信又给我们带来了惊喜,并这次不是新的能力,而是把大家再熟悉不过的二维码换了新的造型. 正式揭晓:微信特制的小程序码.扫一扫新二维码 只要你的微信升级到了 6.5.7 版本,就可以扫码或者 ...
- 微信小程序获取二维码并把logo替换为自己的头像
$avatarUrl = 'http://cms-bucket.nosdn.127.net/2018/05/28/a1a44ffdc2d24f928c1860d4fbf54703.jpeg?image ...
- 微信小程序通过二维码获取参数运行
小程序开发过程中会遇到参数id会通过二维码获取,然后执行接口获取数据,但是难免会遇到带过来的参数出现乱码,这样就需要解码,多个参数时就需要进行处理取我们需要的字段值:小程序开发过程中会遇到参数id会通 ...
- 微信小程序获取二维码参数
var scene = decodeURIComponent(options.scene)
- 用 Python 把微信小程序的二维码转化成图片
官方文档 import cString import requests from tornado.web import authenticated, RequestHandler URL = 'htt ...
- 微信小程序获取二维码API
<%@ WebHandler Language="C#" Class="ce" %> using System; using System.Web; ...
随机推荐
- tomcat源码阅读之BackupManager
一. 配置: <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOpti ...
- Mongodb主从复制 及 副本集+分片集群梳理
转载努力哥原文,原文连接https://www.cnblogs.com/nulige/p/7613721.html 介绍了Mongodb的安装使用,在 MongoDB 中,有两种数据冗余方式,一种 是 ...
- zookkeper原理学习
zookkeper原理学习 https://segmentfault.com/a/1190000014479433 https://www.cnblogs.com/felixzh/p/58692 ...
- LNMP, CentOS7.0+Nginx+Mysql5.7+PHP7环境安装
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.这里和家分享一下,如何在CentOS 7.0上搭建一个这样的环境,其中软件使用yum方式安装. 进入CentOS ...
- Pandas的使用(3)---Pandas的数据结构
Pandas的使用(3) Pandas的数据结构 1.Series 2.DataFrame
- NAND FLASH控制器
一.nand flash访问原理 地址空间概念 nand的编址 nand命令 命令,地址,数据 使用S3C2440的nand flash控制器访问nand flash 前几个编译出来的文件都小于4k ...
- GDI+ 库
uses Winapi.GDIPAPI, Winapi.GDIPOBJ{, Winapi.GDIPUTIL}; procedure TForm1.FormPaint(Sender: TObject); ...
- 如何让classmethod只允许使用用类对象来调用
Django REST framework里面有这样一段代码,在网上查@classonlymethod的意思是使得classmethod只允许使用用类对象来调用 @classonlymethod de ...
- WEKA结果解读
红括号里面,左边是bad的数目,右边是good数目. TP Rate FP Rate Precision Recall F-Measure ROC Area Class 0.536 ...
- windows server core 设置shell 及切换
hkey_local_machine/software/Microsoft/windows nt/currentversion/winlogon/shell 1)windows server 2012 ...