小程序的二维码

admin2年前Laravel627

    public function qrcode()

    {

        $qcode = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $this->Token();

        $data['scene'] = $this->user_id;

        $data['width'] = '280';

        $param = json_encode($data);

        $result = $this->httpRequest($qcode, $param, "POST");

        $imageName = "p_" . date("His", time()) . "_" . rand(1111, 9999) . '.jpg';

        $path = "upload/qrcode/" . date("Ymd");

        if (!is_dir($path)) { //判断目录是否存在 不存在就创建

            mkdir($path, 0777, true);

            chmod($path, 0777);

        }

        $imageSrc = $path . "/" . $imageName; //图片名字

        $msg = file_put_contents($imageSrc, $result);

        $url = $this->domain() . '/' . $imageSrc;

        Db::table('member')->where(array('id' => $this->user_id))->update(['qrcode' => $url]);

        return $url;


    }


  //把请求发送到微信服务器换取二维码

    public function httpRequest($url, $data = '', $method = 'GET')

    {

        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $url);

        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);

        if ($method == 'POST') {

            curl_setopt($curl, CURLOPT_POST, 1);

            if ($data != '') {

                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

            }

        }

        curl_setopt($curl, CURLOPT_TIMEOUT, 30);

        curl_setopt($curl, CURLOPT_HEADER, 0);

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        $result = curl_exec($curl);

        curl_close($curl);

        return $result;

    }


相关文章

压缩图片

public static function size($id, $img) { try { list($width, $height, $img_type, $attr) = @getimages...

下载文件

public function img_url() { $id = request()->param('id', 1122); $info = Db::name('...

微信开放平台-扫码登录

public function wx_info(){    $code = request()->input('code');    if...

发送公众号信息

* 发送消息 */public function tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

设置项目编号

$max = Db::table('member')->max('id') ?? 0; if ($max < 100000) { $cd = $this->create...

修改密码

/** * 修改密码 */publicfunction setpass(){    $type = request()->input('type');// 1...