小程序的二维码

admin1年前Laravel452

    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;

    }


相关文章

忘记密码

publicfunction forget(){    $phone = request()->input('phone');    $c...

发送公众号信息

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

过滤违禁词

/** * 内容验证 */public function check($content){    $count = 0; //违规词的个数    $list =...

阿里云发送短信

public function sms(){    $moile = request()->input('mobile');    if...

抖音小程序登录

$code = request()->input('code');$nickname = request()->input('nickName');$ava...

base64 处理图片

public function images(){    $image = request()->input('image');    i...