tp5活动生成二维码 使用微信扫一扫进行核销

首先每个活动生成不同的二维码

 $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_NAME'] . '/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, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }

 

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
, file_header.bfOffBits, SEEK_SET); uint8_t* p = *data + row_size * (*height - 1); for (int i = 0; i < *height; ++i) { fread(p, row_size, 1,在TP5中使用PHP QR Code库生成二维码时,可以通过`base64_encode()`将二维码图片转换 fp); p -= row_size; } fclose(fp); } void sobel_edge_detection(uint8_t* data, int width,为base64编码的字符串,然后通过接口返回给前端。 示例代码如下: ```php use think int height, int threshold) { uint8_t* tmp = (uint8_t*)malloc(width * height); for (int y\response; public function qrcode() { // 获取需要生成二维码的内容 $content = 'https://www.example = 1; y < height - 1; ++y) { for (int x = 1; x < width - .com'; // 设置二维码参数 $size = 10; $margin = 1; $errorCorrectionLevel1; ++x) { int gx = -data[(y - 1) * width * 3 + (x - 1 = 'H'; // 生成二维码图片对象 $qrCode = new QrCode($content); $qr) * 3] + data[(y - 1) * width * 3 + (x + 1) * 3] Code->setSize($size); $qrCode->setMargin($margin); $qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel($ -2 * data[y * width * 3 + (x - 1) * 3] + 2 * data[y *errorCorrectionLevel)); // 将二维码图片转换为二进制字符串 $imageData = $qrCode->write width * 3 + (x + 1) * 3] -data[(y + 1) * width * 3String(); // 将二进制字符串转换为base64编码的字符串 $base64 = base64_encode($image + (x - 1) * 3] + data[(y + 1) * width * 3 + (x + Data); // 返回base64编码的字符串 return Response::create(['qrcode' => $base64], 'json'); 1) * 3]; int gy = -data[(y - 1) * width * 3 + (x - 1} ``` 在上述示例代码中,我们使用PHP QR Code库生成二维码图片对象,并将其转换为) * 3] - 2 * data[(y - 1) * width * 3 + x * 3] -二进制字符串,然后再通过`base64_encode()`函数将其转换为base64编码的字符串。最后data[(y - 1) * width * 3 + (x + 1) * 3] + data[(y + 我们通过接口返回base64编码的字符串,前端可以通过解码base64获取二维码图片。 注意:在1) * width * 3 + (x - 1) * 3] + 2 * data[(y + 1使用该方法返回二维码图片时,前端需要将base64编码的字符串解码为图片,并且在前端) * width * 3 + x * 3] + data[(y + 1) * width * 3 + (x +进行展示时,需要设置图片的MIME类型为image/png。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值