设为首页 加入收藏

TOP

php 人人商城 生成 临时微信二维码,并保存成海报图片 有效期一个月(一)
2019-08-23 00:37:50 】 浏览:59
Tags: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_toke
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[Linux] LVS虚拟服务器四层负载均.. 下一篇浏览器友好的变量输出

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目