欢迎来到96微信群大全!我们致力于提供最全的微信群二维码大全,让您方便快捷加入微信群。本站是个人微信群经验免费分享网站,请勿用做商业用途
当前位置:96微信群大全 > 微信群学院 > 微信群百科 > PHP微信开微信群大全发之二维码生成类

PHP微信开微信群大全发之二维码生成类

标签:微信,发之,二维,生成 网址:www.96qun.com 网站: 96微信群大全 浏览:2219
这篇文章主要说明了PHP微信开发之二维码生成类,本文利用微信接口完成二维码的生成,并间接给出示例代码,需求的同伴可能考下 ? /** * Created by PhpStorm. * User: bin * Date: 15-1-16 * Time: 上午9:48 */ namespace HomeCommon; // 微信解决类 set_tim

  这篇文章主要说明了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 = ob_get_contents();

  ob_end_clean();

  $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

  return array($return_code, $return_content);

  }

  //下载二维码到效劳器

  protected function DownLoadQr($url,$filestring){

  if($url == ""){

  return false;

  }

  $filename = $filestring.'.jpg';

  ob_start();

  readfile($url);

  $img=ob_get_contents();

  ob_end_clean();

  $size=strlen($img);

  $fp2=fopen('./Uploads/qrcode/'.$filename,"a");

  if(fwrite($fp2,$img) === false){

  $this->ErrorLogger('dolwload image falied. Error Info: 无奈写入图片');

  exit();

  }

  fclose($fp2);

  return './Uploads/qrcode/'.$filename;

  }

  private function ErrorLogger($errMsg){

  $logger = fopen('./ErrorLog.txt', 'a+');

  fwrite($logger, date('Y-m-d H:i:s')." Error Info : ".$errMsg."rn");

  }

  }

,好微信群,最大的微信群,最好的微信群,最多的微信群,最好的微信群,大微信群,好微信群,最好的微信群,微信,微信

本文来自网络采集,文中内容和观点不代表本站立场,本站不保证本文的准确性和真实性.关注微信群大全看更多微信群百科.

上一篇:http://www.96qun.com/weixinqunnew/baike/201608/13_3342.html 下一篇:http://www.96qun.com/weixinqunnew/baike/201608/14_3363.html
版权指引:
  • 本站稿件来互联网采集,如有侵权请联系删除,如需转载请保留出处及原文地址。
  • 96微信群大全:www.96qun.com

    优质微信群

    在线客服 关闭96微信群客服导航
    96微信群二维码大全热门栏目导航
    在线咨询 新手帮助 微信群文章 微信群大全