zoukankan      html  css  js  c++  java
  • 微信生成带参数二维码,跳转公众号

        protected $appid = '';
        protected $secret = '';
        protected $access_tokens;
    
        private function access_token_lst(){
            //获取$access_token
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->secret;
            $result = $this->curl_post($url);
            $access_tokens = json_decode($result, true);
            $this->access_tokens = $access_tokens['access_token'];
        }
       
        public function qr_code()
        {
            //获取access_token
            $this->access_token_lst();
    
            //非必传项
            $rs = $this->getTemporaryQrcode($this->access_tokens, 12345678912345678912345678912345);
         
            $ticket = $rs['ticket'];
            $qrcode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $ticket . "";
            echo "<img src=". $qrcode .">";
        }
    
        //生成二维码
        private 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 = $this->curl_post($url, $momo);
            $rs = json_decode($result, true);
            return $rs;
        }
    
        private 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);
        }

    原文:https://www.cnblogs.com/jiaoda/p/10769129.html

  • 相关阅读:
    iOS 自动化测试踩坑(二):Appium 架构原理、环境命令、定位方式
    干货 | 掌握 Selenium 元素定位,解决 Web 自动化测试痛点
    代理技术哪家强?接口 Mock 测试首选 Charles
    浅谈MVC缓存
    PetaPoco 快速上手
    解释器模式(26)
    享元模式(25)
    中介者模式(24)
    职责链模式(23)
    命令模式(22)
  • 原文地址:https://www.cnblogs.com/junyi-bk/p/13667463.html
Copyright © 2011-2022 走看看