小程序的二维码

admin1年前Laravel566

    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 tosend($openid, $title, $content, $time, $aid){    $tokens = $thi...

手机号替换

 $vv = substr_replace($vv, '****', 3, 4) ....

上传图片

public function image(){    $obFile = request()->file('image');    if...

不重复 的推荐码

public function getcode(){    do {        $code = rand(10000000, 99999...

微信支付V2

   public static function unifiedorder($openid, $out_trade_no, $total_fee, $notify)...

生成唯一的订单号

public function get_order_sn() {     return date('Ymd') ...