php 人人商城 生成 临时微信二维码,并保存成海报图片 有效期一个月
public function getPoster(){
global $_W;
global $_GPC; $mm = pdo_fetch('select nickname,codetime from ' . tablename('ewei_shop_member') . ' where openid =:openid limit 1', array(':openid' => $_W['openid'])); $path = IA_ROOT . '/addons/ewei_shopv2/data/couponposter/' . $_W['uniacid'] . '/';
if (!(is_dir($path)))
{
load()->func('file');
mkdirs($path);
} $openid = $_W['openid']; if($mm['codetime'])$mm['codetime'] = date('Ymd');
$md5 = md5(json_encode(array('openid' => $openid,'version' => 3,'timezone' => $mm['codetime'])));
$file = $md5 . '.jpg'; if(time() > strtotime($mm['codetime']) + 60*60*24*29){
$aa = unlink($path . $file);
}
// var_dump($path . $file);exit;
if (!(is_file($path . $file)))
{
set_time_limit(0);
@ini_set('memory_limit', '256M');
$font = IA_ROOT . '/addons/ewei_shopv2/static/fonts/msyh.ttf';
$target = imagecreatetruecolor(750, 1334);
$bc = imagecolorallocate($target, 0, 3, 51);
$cc = imagecolorallocate($target, 240, 102, 0);
$wc = imagecolorallocate($target, 255, 255, 255);
$yc = imagecolorallocate($target, 255, 255, 0);
$bg = imagecreatefromjpeg(IA_ROOT . '/addons/ewei_shopv2/data/couponposter/poster.jpg');
imagecopy($target, $bg, 0, 0, 0, 0, 750, 1334);
imagedestroy($bg); // $qrcode_file = tomedia($this->createMyShopQrcode($userinfo['id']));
$qrcode_url = $this->getCode();
$qrcode = $this->createImage($qrcode_url); // var_dump($qrcode);
$w = imagesx($qrcode);
$h = imagesy($qrcode);
imagecopyresized($target, $qrcode, 215, 600, 0, 0, 320, 320, $w, $h);
imagedestroy($qrcode); $str1 = $this->getWords($mm['nickname'],3);
imagettftext($target, 22, 0, 180, 302, $bc, $font, $str1);
$str2 = date("Y-m-d",strtotime("+30 day"));
imagettftext($target, 18, 0, 420, 398, $bc, $font, $str2); imagejpeg($target, $path . $file);
imagedestroy($target);
}
$srcc = $_W['siteroot'] . 'addons/ewei_shopv2/data/couponposter/' . $_W['uniacid'] . '/' . $file; $arr = array('code' => 1, 'src' => $srcc);
show_json(1, $arr); }
生成海报
public function getCode(){
global $_W;
global $_GPC;
$sec = m('common')->getSec();
$sec = iunserializer($sec['sec']); $appid = $_W['account']['key'];
$secret = $_W['account']['secret']; $data['openid'] = $_W['openid']; require_once('weixin.class.php'); $wx = new weixin($appid,$secret,''); $mm = pdo_fetch('select id from ' . tablename('ewei_shop_member') . ' where openid=:openid and uniacid=:uniacid limit 1', array(':openid' => $_W['openid'], ':uniacid' => $_W['uniacid']));
$sceneid=intval($mm['id']);
if ($sceneid<=0) {
echo "error!!";
} else {
$result = $wx->_getQRCode($sceneid);
$time = date('Ymd');
pdo_update("ewei_shop_member", array("codetime"=>$time), array( "openid" => $_W['openid'] )); return $result;
} }
生成微信二维码
<?php
// if (!defined('IN_IA')) {
// exit('Access Denied');
// }
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/ class weixin{
private $appid;
private $key;
private $access_token;
private $jsapi_ticket;
private $get_access_token_url='https://api.weixin.qq.com/cgi-bin/token?';
private $menu_url='https://api.weixin.qq.com/cgi-bin/menu/create?access_token=';
private $menu_delete_url='https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=';
private $getcode_url='https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=';
private $oauth2='https://api.weixin.qq.com/sns/oauth2/access_token?';
private $jsapi_ticket_time;
private $access_token_time;
public $menu;
public function __construct($appid,$key,$access_token) {
//$this->extract= sp_get_option('extract');
$this->appid=$appid;
$this->key=$key;
$this->access_token=$this->get_access_token();//access_token_time }
public function get_jsapi_ticket(){
if($this->$jsapi_ticket_time<time()-7200){
$url='https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$this->access_token.'&type=jsapi';
$result=$this->https($url);
$result=json_decode($result,true);
if($result['ticket']){
$this->jsapi_ticket=$result['ticket'];
$this->$jsapi_ticket_time=time();
//$res = sp_set_option('extract', $this->extract);
}
else{
print_r($result);
exit();
}
}
return $this->jsapi_ticket;
}
public function get_access_token(){
if($this->access_token_time<time()-7200){
$url=$this->get_access_token_url."grant_type=client_credential&appid=".$this->appid."&secret=".$this->key;
$result=$this->https($url);
$result=json_decode($result,true);
if($result['access_token']){
$this->access_token=$result['access_token'];
$this->access_token_time=time();
//$res = sp_set_option('extract', $this->extract);
}
else{
print_r($result);
exit();
}
}
return $this->access_token;
}
public function get_oauth2($code){
$url=$this->oauth2."appid=".$this->appid."&secret=".$this->key."&code=".$code."&grant_type=authorization_code";
$result=$this->https($url);
$result=json_decode($result,true);
return $result;
exit;
} public function get_userinfo($openid){
//需要关注的url
$url="https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$this->access_token."&openid=".$openid."&lang=zh_CN";
//无需关注
//$url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$this->access_token."&openid=".$openid."&lang=zh_CN";
$result=$this->https($url);
$result=json_decode($result,true);
return $result;
exit;
}
public function get_qrcode($id){
$url=$this->getcode_url.$this->access_token;
$data='{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": '.$id.'}}}';
$result=$this->https($url,$data,'json');
$result=json_decode($result,true);
return $result;
exit;
}
public function updata_menu(){
$url=$this->menu_url.$this->access_token;
$this->menu=htmlspecialchars_decode($this->menu);
$data=$this->menu;
$result=$this->https($url,$data,'json');
$result=json_decode($result,true);
return $result;
exit;
}
public function https($url,$data='',$method='get'){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
if($method=='POST'){
curl_setopt($ch, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
if ($data != ''){
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
}
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
if($method=='json'){
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data))
);
}
else{
curl_setopt($ch, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
/**
* 首先创建二维码ticket
* @param string $sceneid 场景值ID
* @param string $type 值为'temp'的时候生成临时二维码
* @param string $expire_seconds 二维码过期时间
* @return string 二维码ticket
*/
public function _getTicket($sceneid,$type='temp',$expire_seconds=604800){
if($type=='temp'){
$data['expire_seconds']=604800;
$data['action_name']='QR_SCENE';
$data['action_info']['scene']['scene_id']=$sceneid;
}else{
$data['action_name']='QR_LIMIT_SCENE';
$data['action_info']['scene']['scene_id']=$sceneid;
} $args =json_encode($data);
$curl = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$this->access_token;
$content = $this->https($curl,$args,'POST');
$cont = json_decode($content); return $cont->ticket;
}
//然后凭借ticket到指定URL换取二维码
public function _getQRCode($sceneid,$type='temp1',$expire_seconds=2592000){
$ticket = $this->_getTicket($sceneid,$type,$expire_seconds);
$curl = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode($ticket);
$content = $this->https($curl);
return $curl;
}
}
微信类
php 人人商城 生成 临时微信二维码,并保存成海报图片 有效期一个月的更多相关文章
- js生成带有logo的二维码并保存成图片下载
生成二维码,需要依赖jquery,先引入一个jquery,然后需要一个插件改变过了jquery-qrcode.js 插件代码(需要的自己打开看): /*! jquery-qrcode v0.14.0 ...
- js生成二维码并保存成图片下载
我这里使用是jQuery,和jquery.qrcode.js,需要的可以自己找链接下载.示例代码仅做参考 html代码: <a id="downloadLink">&l ...
- C#获取微信二维码显示到wpf
微信的api开放的二维码是一个链接地址,而我们要将这个二维码显示到客户端.方式很多,今天我们讲其中一种. /// <summary> /// 获取图片路径 /// </summary ...
- 微信公众号开发C#系列-11、生成带参数二维码应用场景
1.概述 我们在微信公众号开发C#系列-7.消息管理-接收事件推送章节有对扫描带参数二维码事件的处理做了讲解.本篇主要讲解通过微信公众号开发平台提供的接口生成带参数的二维码及应用场景. 微信公众号平台 ...
- 微信二维码添加logo
生成带参数的二维码 为了满足用户渠道推广分析和用户帐号绑定等场景的需要,公众平台提供了生成带参数二维码的接口.使用该接口可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送. 目前有 ...
- 微信二维码支付-模式一(PC端,解决中文乱码问题)
近期公司调完银联,调支付宝,调完支付宝调微信.说实话微信的帮助文档确实是烂,而且有没有技术支持,害的我头发都掉了一桌.不说废话了,看代码. 首先登陆微信的公众平台(微信的服务号不是订阅号),然后选择微 ...
- ZXing 生成、读取二维码(带logo)
前言 ZXing,一个支持在图像中解码和生成条形码(如二维码.PDF 417.EAN.UPC.Aztec.Data Matrix.Codabar)的库.ZXing(“zebra crossing”)是 ...
- PHP生成小程序二维码合成图片生成文字
这部分代码是写在项目上的代码,THINKPHP3.1如果迁移到其他的地方应该要稍稍改动一下以适合自己的项目 function get_bbox($text,$fsize,$ffile){ return ...
- C# 利用ZXing.Net来生成条形码和二维码
本文是利用ZXing.Net在WinForm中生成条形码,二维码的小例子,仅供学习分享使用,如有不足之处,还请指正. 什么是ZXing.Net? ZXing是一个开放源码的,用Java实现的多种格式的 ...
随机推荐
- 斗鱼扩展--DouyuRoom使用说明(十四)
1.从 https://pan.baidu.com/s/1yBfZFtcakbDxmyas0VCpRw 下载 DouyuRoom.zip 然后解压到一个目录,我是放在C盘根目录下的,你们随意.然后解压 ...
- c# cook book -Linq 关于Object的比较
实际项目中经常用到 Union,Distinct,INtersect,Execpt对列表进行处理 一般来说要首先重写 Equals 和GetHashCode方法 首先看为重写的情况: namespac ...
- Mysql慢查询 [第二篇]
一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdu ...
- MyEclipse快捷键大全,很实用
Eclipse本身很快的,但是加上了myeclipse后,就狂占内存,而且速度狂慢,那如何让Eclipse拖着myeclipse狂飚呢?这里提供一个: 技巧:取消自动validation valid ...
- 手把手教你用android studio创建第一个安卓程序加载html5页面(二)
经过上一篇,我们已经可以打开html页面了,但是有很多细节方面的内容我们还需要调整. 打开链接的问题 细心的网友可能已经发现,打开百度页面后,点击顶部的链接,会在手机的浏览器中打开相应的页面,这显然不 ...
- ASP.NET MVC 音乐商店 - 1 创建项目
我们的项目从在 Visual Studio 中的文件菜单中选择“新建”,选择“项目”开始. 然后,选择 C# 中的 Web 模板组,在右边的项目模板中选择 ASP.NET MVC3 Web 应用程序, ...
- AOSP 源码整编单编
<AOSP 源码下载>完成后,就可以开编了. 整编 整编,顾名思义就是编译整个 Android 源码,最终 out 目录会生成几个重要的镜像文件,其中有 system.img.userda ...
- scss的使用方式(环境搭建)
我用的是Koala. IDE是intellij_idea(其他IDE也可) 下载Koala:http://koala-app.com/ 2.安装(选好位置,下一步即可) 3.打开Koala,创建项目 ...
- Android Studio使用OpenCV的配置方法
1.下载 进入官网(http://opencv.org/)下载OpenCV4Android并解压.目录结构如下图所示. 其中,sdk目录即是我们开发opencv所需要的类库:samples目录中存放着 ...
- ansible使用2-命令
并发与shell # bruce用户身份,-m指定模块名称,默认模块名command,all所有目标主机,也可以指定组名或者主机名 ansible all -m ping -u bruce # bru ...