• php 通过扫描二维码关注公众号


    class Wxfollow

    {

        protected $appid = 'wxf1d959b99f33b156';

        protected $secret = '248f3a560604555ec96215c085cb2723';

        protected $url = "";

        protected $access_tokens = "";

     

     

        public function __construct()

        {

            //获取$access_token

            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->secret . "";

            $result = curl_post($url);

            $access_tokens = json_decode($result, true);

            $this->access_tokens = $access_tokens['access_token'];

     

        }

        public function Follow(){

            //非必传项

            $rs = $this->getTemporaryQrcode($this->access_tokens, 123);

            $ticket = $rs['ticket'];

            $qrcode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $ticket . "";

            ///打印二维码显示

            jumpUrl($qrcode);

        }

     

        //生成二维码

        public function getTemporaryQrcode($access_tokens,$orderId)

        {

            $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" .$access_tokens . "";

            //生成二维码需要的参数

            $qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": ' . $orderId . '}}}';

            $momo = json_decode($qrcode, true);

     

            $result = curl_post($url, $momo);

            $rs = json_decode($result, true);

            return $rs;

        }

       function curl_post($url, array $params = array())

       {

        $data_string = json_encode($params);

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

        curl_setopt($ch, CURLOPT_HTTPHEADER,

            array(

                'Content-Type: application/json'

            )

        );

        $data = curl_exec($ch);

        curl_close($ch);

        return ($data);

      }

    }

  • 相关阅读:
    laravel md5+salt 密码
    sql语句 当前时间查找重复 时间戳转换
    Supesite 参数说明
    ajax
    PDO操作
    laravel paginate动态分页
    PHP iconv()函数转字符编码的问题(转)
    计算几何基础模板(2014.10.6一直沿用)
    hdu 4893
    2014 ACM/ICPC 鞍山赛区网络赛(清华命题)
  • 原文地址:https://www.cnblogs.com/jiaoda/p/10769129.html
Copyright © 2020-2023  润新知