国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

PH,P微信開發之二維碼生成類

2019-11-02 15:13:26
字體:
來源:轉載
供稿:網友

   這篇文章主要介紹了PHP微信開發之二維碼生成類,本文使用微信接口實現二維碼的生成,并直接給出示例代碼,需要的朋友可以參考下

  ?

  /**

  * Created by PhpStorm.

  * User: bin

  * Date: 15-1-16

  * Time: 上午9:48

  */

  namespace HomeCommon;

  // 微信處理類

  set_time_limit(30);

  class Weixin{

  //構造方法

  static $qrcode_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?";

  static $token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&";

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

  //生成二維碼

  public function getEwm($wechatid,$fqid,$type = 1){

  $wechat = M('Member_public')->where(array('id'=> $wechatid))->find();

  $appid = $wechat['appid'];

  $secret = $wechat['secret'];

  $ACCESS_TOKEN = $this->getToken($appid,$secret);

  $url = $this->getQrcodeurl($ACCESS_TOKEN,$fqid,1);

  return DownLoadQr($url,time());

  }

  protected function getQrcodeurl($ACCESS_TOKEN,$fqid,$type = 1){

  $url = self::$qrcode_url.'access_token='.$ACCESS_TOKEN;

  if($type == 1){

  //生成永久二維碼

  $qrcode= '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": '.$fqid.'}}}';

  }else{

  //生成臨時二維碼

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

  }

  $result = $this->http_post_data($url,$qrcode);

  $oo = json_decode($result[1]);

  if(!$oo->ticket){

  $this->ErrorLogger('getQrcodeurl falied. Error Info: getQrcodeurl get failed');

  exit();

  }

  $url = self::$qrcode_get_url.'ticket='.$oo->ticket.'';

  return $url;

  }

  protected function getToken($appid,$secret){

  $ACCESS_TOKEN = file_get_contents(self::$token_url."appid=$appid&secret=$secret");

  $ACCESS_TOKEN = json_decode($ACCESS_TOKEN);

  $ACCESS_TOKEN = $ACCESS_TOKEN->access_token;

  return $ACCESS_TOKEN;

  }

  protected function http_post_data($url, $data_string) {

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_POST, 1);

  curl_setopt($ch, CURLOPT_URL, $url);

  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

  curl_setopt($ch, CURLOPT_HTTPHEADER, array(

  'Content-Type: application/json; charset=utf-8',

  'Content-Length: ' . strlen($data_string))

  );

  ob_start();

  curl_exec($ch);

  if (curl_errno($ch)) {

  $this->ErrorLogger('curl falied. Error Info: '.curl_error($ch));

  }

  $return_content =

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彰武县| 神木县| 新蔡县| 桐柏县| 西藏| 清河县| 湘潭市| 眉山市| 库车县| 垣曲县| 宜黄县| 星子县| 呼玛县| 辽源市| 博客| 隆德县| 常宁市| 达孜县| 克东县| 兰考县| 望谟县| 柏乡县| 台东市| 龙门县| 喀喇| 洪洞县| 广平县| 鹰潭市| 湛江市| 芦山县| 额敏县| 东源县| 诸暨市| 从化市| 尉犁县| 水城县| 富裕县| 辽阳市| 万全县| 九寨沟县| 全州县|