php生成二维码

<?php 
/*我的账号*/
namespace app\usercenter\controller;
use app\usercenter\Core;
class Userinfo extends Core{
public function index(){
if($post['from'] == 'wxmini'){
   // 小程序二维码
   $config["appid"] = 'wxc-----a';
   $config["appsecret"] = '42ca------2';
   $Qrcode = new \WeMini\Qrcode( $config );
   $Qrcode = $Qrcode->createMiniScene('hfffs','pages/default/index');
} else {
   $url = $_SERVER["REQUEST_SCHEME"].'://www.'.Y('site')['domain']."/index/mall/detail/?goods_id=".$post['id'].'fromuid='.UID; 
   $url = $_SERVER["REQUEST_SCHEME"].'://www.'.Y('site')['domain'].'/api/common/get_qrcode/?url='. urlencode($url);
   $Qrcode = file_get_contents($url);
}
}
}
Qrcode.php
<?php
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;

/**
 * 微信小程序二维码管理
 * Class Qrcode
 * @package WeMini
 */
class Qrcode extends BasicWeChat
{

    /**
     * 获取小程序码(永久有效)
     * 接口A: 适用于需要的码数量较少的业务场景
     * @param string $path 不能为空,最大长度 128 字节
     * @param integer $width 二维码的宽度
     * @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
     * @param array $line_color auto_color 为 false 时生效
     * @param null|string $outType 输出类型
     * @return array|string
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     */
    public function createMiniPath($path, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"], $outType = null)
    {
        $url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        $data = ['path' => $path, 'width' => $width, 'auto_color' => $auto_color, 'line_color' => $line_color];
        $result = Tools::post($url, Tools::arr2json($data));
        if (json_decode($result)) {
            return Tools::json2arr($result);
        }
        return is_null($outType) ? $result : $outType($result);
    }

    /**
     * 获取小程序码(永久有效)
     * 接口B:适用于需要的码数量极多的业务场景
     * @param string $scene 最大32个可见字符,只支持数字
     * @param string $page 必须是已经发布的小程序存在的页面
     * @param integer $width 二维码的宽度
     * @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
     * @param array $line_color auto_color 为 false 时生效
     * @param null|string $outType 输出类型
     * @return array|string
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     */
    public function createMiniScene($scene, $page, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"], $outType = null)
    {
        $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN';
        $data = ['scene' => $scene, 'width' => $width, 'auto_color' => $auto_color, 'page' => $page, 'line_color' => $line_color];
        $this->registerApi($url, __FUNCTION__, func_get_args());
        $result = Tools::post($url, Tools::arr2json($data));
        if (json_decode($result)) {
            return Tools::json2arr($result);
        }
        return is_null($outType) ? $result : $outType($result);
    }

    /**
     * 获取小程序二维码(永久有效)
     * 接口C:适用于需要的码数量较少的业务场景
     * @param string $path 不能为空,最大长度 128 字节
     * @param integer $width 二维码的宽度
     * @param null|string $outType 输出类型
     * @return array|string
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     */
    public function createDefault($path, $width = 430, $outType = null)
    {
        $url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        $result = Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width]));
        if (json_decode($result)) {
            return Tools::json2arr($result);
        }
        return is_null($outType) ? $result : $outType($result);
    }

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值