IT门户网,专注电脑知识与技术及手机硬件信息服务网站!

当前位置:IT门户网 > 网络知识 > 网站seo >

PH,P微信开拓之二维码生成类

时间:2021-09-14    来源:IT门户网    人气:

  * 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 =

相关文章

网站seo排行榜

更多>>

网络知识排行榜

更多>>

系统教程排行榜

更多>>

服务号