小程序的二维码

admin9个月前Laravel389

    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 function register(){    $mobile = request()->input('mobile');   &nb...

生成二维码

public function qrcode($uid){    require_once base_path() . '/public/phpqrcode/phpqrco...

微信退款v3

/** * 微信 退款 操作 */ public function refund($out_trade_no, $refund_money) { $time = time();...

修改密码

public function setpass(){    $mobile = request()->input('mobile');   &nbs...

laravel 加cache锁

use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Cache; $lock = Ca...

百度浏览器中视频悬浮

  <video class="html5-video"                poster=...