<"https://api.weixin.qq.com/cgi-bin/qrcode/create";
  static $token_url = "https://api.weixin.qq.com/cgi-bin/token";
  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."\r\n");
  }

}

标签:
PHP,微信开发,二维码生成类

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“PHP微信开发之二维码生成类”

暂无“PHP微信开发之二维码生成类”评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。