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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /hermes/bosnacweb04/bosnacweb04ac/b1072/ipg.liuyuan7592410/lib/

Linux boscustweb5001.eigbox.net 5.4.91 #1 SMP Wed Jan 20 18:10:28 EST 2021 x86_64
Upload File :
Current File : /hermes/bosnacweb04/bosnacweb04ac/b1072/ipg.liuyuan7592410/lib/WeChat.class.php

<?PHP
/**
 * version = debug 0.2 2018/11/22 添加短信验证函数
 * verion = debug 0.1 2018/11/22
 * 微信公众平台操作类
 */
 require_once("../lib/my_php_tools.php");
 require_once("../lib/mysqli_db.class.php");

 class WeChat {
 	private $_appid;
 	private $_appsecret;
 	private $_token; //公众平台请求开发者时需要的标记
 	private $_obj_db;

 	private $_msg_template=array(
 		'msg_basic' => '<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType>%s</xml>', //被动回复消息基本XML模板
 		'text' => '<Content><![CDATA[%s]]></Content>',//文件回复XML模板
 		'image' => '<Image><MediaId><![CDATA[%s]]></MediaId></Image>',//图片回复XML模板
 		'voice' => '<Voice><MediaId><![CDATA[%s]]></MediaId></Voice>',//语音回复XML模板
 		'video' => '<Video><MediaId><![CDATA[%s]]></MediaId><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description></Video>',//视频回复XML模板
 		'music' => '<Music><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description><MusicUrl><![CDATA[%s]]></MusicUrl><HQMusicUrl><![CDATA[%s]]></HQMusicUrl><ThumbMediaId><![CDATA[%s]]></ThumbMediaId></Music>',//音乐回复XML模板
 		'news' => '<ArticleCount>%s</ArticleCount><Articles>%s</Articles>',//图文消息回复XML模板
 		'news_items' => '<item><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description><PicUrl><![CDATA[%s]]></PicUrl><Url><![CDATA[%s]]></Url></item>', //某个图文消息模板
 		'sms_verify' => '<xml><to><![CDATA[%s]]></to><sender_id><![CDATA[%s]]></sender_id><msg_id><![CDATA[%s]]></msg_id><msg><![CDATA[%s]]></msg></xml>' //短信验证模板
  		);

 	//表示QRCode的类型
 	const QRCODE_TYPE_TEMP = 1;
 	const QRCODE_TYPE_LIMIT = 2;
 	const QRCODE_TYPE_LIMIT_STR = 3;

 	public function __construct($id=NULL,$secret=NULL,$token=NULL){
		$this->setWechat($id,$secret,$token);
	}

 	/**
 	 * 设置微信公众号的id,secret,token
 	 * @param [type] $id     [description]
 	 * @param [type] $secret [description]
 	 * @param [type] $token  [description]
 	 */
 	public function setWechat($id,$secret,$token){
  		$this->_appid=$id;
 		$this->_appsecret=$secret;
 		$this->_token=$token;		
 	}

 	private function _getSysConfig($item){
 		$sys_info=json_decode($this->_obj_db->getdata("t_sys_config","`value`","item='".$item."'"));
 		$value=$sys_info[0]->value;
 		return $value;
 	}

 	private function _getNextSMSMsgID(){
 		$sms_info=json_decode($this->_obj_db->getdata("t_sms_record","max(msg_id) as msg_id"),"1");
 		if($sms_info[0]->msg_id!=NULL)
 			$msg_id="00000000".strval(intval($sms_info[0]->msg_id)+1);
 		else
 			$msg_id="0000000000001";
 		return substr($msg_id,-8);
 	}

 	/**
 	 *
 	 */
 	public function sendSMSVerify($cell_phone,$nc_open_id){
 		$verify_code=rand_digits(6);
 		$url=$this->_getSysConfig("sms_gw_api_url");
 		$to=$cell_phone;
 		$from=$this->_getSysConfig("sms_gw_uid");
 		$msg_id=$this->_getNextSMSMsgID();
 		$msg='Nail Club III verification code is '.$verify_code;
 		$data=sprintf($this->_msg_template['sms_verify'],$to,$from,$msg_id,$msg);

		$json_response=$this->_requestPost($url,$data,false);
		$json_response=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $json_response);
 		$response=json_decode($json_response);

 		if($response->result=='success'){ //发送短信验证码成功,将验证码信息写入库,以便验证时使用
 			$data='[{
 				"cell_num":"'.$cell_phone.'",
 				"sms_vrf_code":"'.$verify_code.'",
 				"sms_code_expire":"'.date("Y-m-d H:i:s",time()+60*15).'"  
 			}]';					
 			$this->_obj_db->savedata('t_usr_account',$data,'nc_open_id="'.$nc_open_id.'"'); 
 			return true;
 		} else {
 			return false;
 		}

 	}

 	public function getUsrStatus($wc_open_id){
 		$url= 'http://nailclub3.com';
 	}

 	/**
 	 * 设置自定义菜单,$menu是Json格式菜单定义
 	 * @param  [type] $menu [description]
 	 * @return [type]       [description]
 	 */
 	public function menuSet($menu){
 		$url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$this->_getAccessToken();
 		$data = $menu;
 		$result = $this->_requestPost($url,$data);
 		$result_obj = json_decode($result);
 		if($result_obj->errcode == 0){
 			return true;
 		} else {
 			echo $result_obj->errmsg, '<br>';
 			return false;
 		}
 	}

 	/**
 	 * 菜单删除
 	 */
 	public function menuDelete(){
 		$url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token='.$this->_getAccessToken();
 		$result = $this->_requestGet($url);
 		$result_obj = json_decode($result);
 		if ($result_obj->errcode == 0){
 			return true;
 		} else {
 			return false;
 		}
 	}

 	public function connectDB($host,$usrname,$pwd,$db_name){
 		return $this->_obj_db=new mysql_db($host,$usrname,$pwd,$db_name);
 	}

 	private function _createNewncusr($wx_open_id,$ref_by){
		$data='[{
				"wx_open_id":"%s",
				"nc_open_id":"%s",
				"ref_by":"%s",
				"create_time":"%s",
				"status":"0"
				}]';
		$nc_open_id=$this->_createncid();
		$this->_log("create a nail club open id:[".$nc_open_id."]");
		$data=sprintf($data,$wx_open_id,$nc_open_id,$ref_by,date("Y-m-d H:i:s"));
		$this->_obj_db->savedata('t_usr_account',$data);
 	}

 	private function _whoisvisiter($wc_open_id){
 		$this->_log("running _whoisvisiter");
 		$json_user=$this->_obj_db->getdata("t_usr_account","nc_open_id,nc_id,status","wx_open_id='".$wc_open_id."'");
 		$this->_log("get json data from DB");
 		$user=json_decode($json_user);
 		if(count($user)==0){ //首次访问的wechat用户
 			$this->_log("before create nail club user account");
 			$this->_createNewncusr($wc_open_id,"");
 			return -1;		//首次访问,创建一nc账户,
 		} else{
 			return $user[0]->status;
  		}
 	}

 	private function _createncid(){
 		return "ncc".rand_str(20,time());
 	}

 	public function receivePOSTXML(){
  		//获取请求时的POST XML字符串
 		//$_POST,不是key/value型,因此不能使用该数组
 //		$xml_str = $GLOBALS['HTTP_RAW_POST_DATA'];    //php4,5 use this
 		$xml_str = file_get_contents("php://input");  //php7 use this

 		$this->_log("received xml msg: ".$xml_str);

 		//如果没有post数据,响应空字符串,表示结束
 		if(empty($xml_str)){
 			die('');
 		}
 		//解析该xml字符串,利用simpleXML
 		libxml_disable_entity_loader(true); //禁止xml实体解析,防止xml注入
 		$request_xml = simplexml_load_string($xml_str,'SimpleXMLElement',LIBXML_NOCDATA); 	

 		return $request_xml;		
  	}

 	public function responseMSG($rq_xml=NULL){
 		$this->_log("received msg from : [".$rq_xml->FromUserName."]");
 		$this->_log(count((array)$rq_xml));
  		if ($rq_xml!=NULL){
	 		$request_xml =  $rq_xml;		
	 		$this->_log("responseMSG processing 1");	
 		}else{
 			$request_xml = $this->receivePOSTXML();
 	 		$this->_log("responseMSG processing 2");	
		} 	

 		switch($this->_whoisvisiter($request_xml->FromUserName)){
 			case "-1":
 			case "0":
 			case "1":
 			case "2":
 			case "3":
 			case "4":
 			case "5":
 			case "6":
 				$this->responseMSG_verified($request_xml);
 				$this->_log("responseMSG processing 3");	
 			break;
 			case "64":
 				$data="内部人员使用接口尚未完成";
 				$this->replyText($request_xml->FromUserName,$request_xml->ToUserName,$data);
 			break;
  		}

		$this->_log("responseMSG processing 4");	
	}

 	public function responseMSG_verified($rq_xml=NULL) {

 		if ($rq_xml!=NULL){
	 		$request_xml = $rq_xml; 			
 		}else{
 			$request_xml = $this->receivePOSTXML();
 		}
		//从一个字符串获取simpleXML对象
 		//判断该消息的类型通过元素:MsgType
 		switch ($request_xml->MsgType){
 			case 'event': //事件类型
 				//判断具体的事件类型(关注,取消,点击)
 				$event=$request_xml->Event;
 				$this->_log("receive event msg, [msgType]=".$event);
 				if ('subscribe'==$event){ //关注事件
 					$this->_doSubscribe($request_xml);
 				} elseif('CLICK'==$event){ //菜单点击事件
 					$this->_doClick($request_xml); 
 				} elseif('scancode_push'==$event){ //扫描二维码
 					$this->_doScancode_push($request_xml);
 				} elseif('scancode_waitmsg'==$event){ //扫描二维码消息接收中
 					$this->_doScancode_waitmsg($request_xml);
 				} elseif('SCAN'==$event){   //扫描二维码

 				}
 				break;
 			case 'text': //文本消息
 				$this->_log("receive text msg, [content]=".$request_xml->Content);
 				 $this->_doText($request_xml);
 				break;
 			case 'image': //图片消息
 				$this->_doImage($request_xml);
 				break;
 			case 'voice': //语音消息
 				$this->doVoice($request_xml);
 				break;
 			case 'video': //视频消息
 				$this->doVideo($request_xml);
 				break;
 			case 'shortvideo': //小视频消息
 				$this->_doShortVideo($request_xml);
 				break;
 			case 'location': //位置消息
 				$this->_doLocation($request_xml);
 				break;
 			case 'link': //链接消息
 				$this->_doLink($request_xml);
 				break;
 			default:
 		}
 	}

 	private function _doText($request_xml){
 		//获取文本内容
 		$content=$request_xml->Content;
 		//对内容进行判断
 		if('?'==$content){
 			//显示帮助信息
 			$response_content = '输入对应序号或名称,完成相应操作'."\n".'[1]预约服务'."\n"."[2]查看余额"."\n"."[3]报名培训";
 		} elseif('1'==strtolower($content)||'php'==strtolower($content)){
 			$response_content='预约服务'."\n".'http://nailclub3.com/';
 		} elseif('2'==strtolower($content)||'java'==strtolower($content)){
 			$response_content='查看余额'."\n".'http://nailclub3.com/';
 		} elseif('3'==strtolower($content)||'c++'==strtolower($content)){
 			$response_content='培训报名'."\n".'http://nailclub3.com/';
 		} elseif('图片' == $content){
 			$file_list = array('./picture/French1.jpg','./picture/French2.jpg','./picture/French3.jpg');
 			$rand_index=mt_rand(0,count($file_list)-1);
 			$this->_msgImage($request_xml->FromUserName,$request_xml->ToUserName,$file_list[$rand_index]);
 		} elseif('语音'==$content){
 			$file_list = array('./voice/voice1.amr');
 			$rand_index=mt_rand(0,count($file_list)-1);
 			$this->_msgVoice($request_xml->FromUserName,$request_xml->ToUserName,$file_list[$rand_index]);
 		} elseif('歌曲'==$content){
 			$music_url='http://nailclub3.com/wx/music/zhangbichen hongmeigui.mp3';
 			$hq_music_url='http://nailclub3.com/wx/music/zhangbichen hongmeigui.mp3';
 			$thumb_file='./picture/zhangbichen4.jpg';
 			$title='张碧晨 红玫瑰';
 			$description='原唱陈奕迅,张碧晨唱出了不一样的味道,值得反复倾听。';
 			$this->_msgMusic($request_xml->FromUserName,$request_xml->ToUserName,$music_url,$hq_music_url,$thumb_file,false,$title,$description);
 		} elseif('新闻'==$content){
 			$item_list = array(
 				array('title'=>'多伦多美甲行业现状','desc'=>'美甲行业因为入门门槛低,没有硬性执照要求,容易开业,因此是很多从中国来的第一代移民做生意的选择,但是...','picurl'=>'http://nailclub3.com/wx/picture/1.jpg','url'=>'http://nailclub3.com'),
				array('title'=>'多伦多日式美甲哪里找?','desc'=>'亚裔人中,引导美甲潮流的,应该是日式美甲,日式美甲做工精致,工艺复杂,对美甲师要求相对也高,没有经过系统培训,和足够的实际操练,很难达到客户的期望,今天就给大家介绍一个美甲店,','picurl'=>'http://nailclub3.com/wx/picture/2.jpg','url'=>'http://nailclub3.com'),
				array('title'=>'多伦多美甲培训','desc'=>'美甲行业是一个师傅带徒弟的行业,但是往往教会了徒弟,饿死了师父,所以在店里学徒,往往学习时间长,学的不系统...','picurl'=>'http://nailclub3.com/wx/picture/3.jpg','url'=>'http://nailclub3.com'),
				array('title'=>'法式美甲图集','desc'=>'法式水晶简约,大方,深受许多职场女性的厚爱,现在,从传统的白边法式水晶甲衍生出许多新的设计,今天就给大家介绍一些...','picurl'=>'http://nailclub3.com/wx/picture/4.jpg','url'=>'http://nailclub3.com')
 				);
 			$this->_msgNews($request_xml->FromUserName,$request_xml->ToUserName,$item_list);
 		}
 		else{
 	//		$response_content='输入对应序列号或名称,获取相应资源'."\n"."[1]PHP"."\n"."[2]Java"."\n"."[3]C++";
 	//		通过小黄鸡(聊天机器人),响应给微信用户
 			$url="http://www.xiaohuangji.com/ajax.php";
 			$data['para']=$content;
 			$response_content=$this->_requestPost($url,$data,false);
 		}

 		$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$response_content);
 	}

 	/**
 	 * 处理图片响应数据
 	 */
 	private function _doImage($request_xml){
 		$saved_file_name=$this->_create_file_name($request_xml);
 		$this->_log("receive a file, and save it as: ".$saved_file_name);
 		$this->downloadMedia($request_xml->MediaId,$saved_file_name);
 		$content="我们已经收到并保存您上传的图片";
 		$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$content);
 	}

 	private function _doLocation(){
 	//	$content='你的坐标为,经度:'.$request_xml->Location_Y.",维度:".$request_xml->Location_X."\n".'你所在的位置为:'.$request_xml->Label;
 	//	$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$content);
 	//	利用位置获取信息
 	//	百度LBS原型范围查询
	 	$url = 'http://api.map.baidu.com/place/v2/search?query=%s$location=$s&radius=%s&output=%s&ak=%s';
 		$query = '银行'; //查询银行
 		$location = $request_xml->Location_Y.','.$request_xml->Location_Y; //查询中心点的经纬度
 		$radius = 2000; //查询2公里内
 		$output = 'json'; //返回数据的格式
 		$ak = 'OBD16igkrng0V6VqT5RWIP6z'; //百度web服务API生成的密钥

 		$url=sprintf($url,urlencode($query),$location,$radius,$output,$ak); //把$url里面5个%s字符串依次分别用指定字符串代替
 //		file_put_contents('./url',$url); //输出到当前的文件系统
 		$result = $this->_requestGet($url,false); //GET发生发送请求到$url
 		$result_obj = json_decode($result); //JSON解码

 		$re_list=array();
 		foreach ($result_obj->results as $re) {
 			$r['name']=$re->name;
 			$r['address']=$re->addresss;
 			$re_list[]=implode('-',$r);
 		}
 		$re_str=implode('\n',$re_list);

 		$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$content);
 	}


 	/**
 	 * 用于处理关注事件的方法
 	 * @param  [type] $request_xml  事件信息对象
 	 * @return [type]              [description]
 	 */
 	private function _doSubscribe($request_xml){
 		// 利用消息的发送,完成向关注用户打招呼的功能。
 		$content = "感谢您关注Nail Club III微信公众号,我们的公众号页面正在建设中,敬请期待。\n地址:8601 Warden Ave, Unit 11, Markham ON Canada \n电话:905-489-1992 \n网址:http://nailclub3.com";
  		$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$content);
 	}

 	private function _doClick($request_xml){
 		$content = '您点击了['.$request_xml->EventKey.']按钮';
 		$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$content);
 	}

 	private function _doScancode_push($request_xml){
 		$content= $request_xml->ScanCodeInfo->ScanResult;
  		$this->_msgText($request_xml->FromUserName,$request_xml->ToUserName,$content);
 	}

 	public function replyText($to,$from,$content){
		$this->_msgText($to,$from,$content); 		
 	}

 	/**
 	 * 发送文本信息
 	 * @param  [type] $to      目标用户ID
 	 * @param  [type] $from    来源用户ID
 	 * @param  [type] $content 内容
 	 * @return [type]          [description]
 	 */
 	private function _msgText($to,$from,$content){
 		$msg_body = sprintf($this->_msg_template['text'],$content);
		$this->_msg($to,$from,'text',$msg_body);
  	}


 	/**
 	 * 发送图片消息
 	 * @param  [type] $to   [description]
 	 * @param  [type] $from [description]
 	 * @param  [type] $file 图片文件地址
 	 * @return [type]       [description]
 	 */
 	private function _msgImage($to,$from,$file,$is_id=false){
 		if($is_id){
 			$media_id=$file;
 		} else{
	 		//上传图片到微信公众服务器,获得mediaID
	 		$result_obj = $this->uploadTmp($file,'image');
	 		$media_id = $result_obj->media_id;			
 		}
 		//平凑图像类消息xml文件
 		$msg_body = sprintf($this->_msg_template['image'],$media_id);
 		$this->_msg($to,$from,'image',$msg_body);
  	}


 	private function _msgVoice($to,$from,$file,$is_id=false){
 		if($is_id){
 			$media_id=$file;
 		} else{
	 		//上传语音到微信公众服务器,获得mediaID
	 		$result_obj = $this->uploadTmp($file,'voice');
	 		$media_id = $result_obj->media_id;			
 		}
 		//拼凑语音类消息xml文件
 		$msg_body = sprintf($this->_msg_template['voice'],$media_id);
 		$this->_msg($to,$from,'voice',$msg_body);
 	}

 	private function _msgVideo($to,$from,$title,$description,$file,$is_id=false){
 		if($is_id){
 			$media_id=$file;
 		} else {
 			$result_obj = $this->uploadTmp($file,'video');
 			$media_id = $result_obj->media_id;
 		}
 		$msg_body = sprintf($this->_msg_template['video'],$media_id,$title,$description);
 		$this->_msg($to,$from,'video',$msg_body);
 	}

 	private function _msgMusic($to,$from,$music_url,$hq_music_url,$thumb_file,$is_id=false,$title='',$description=''){
 		if($is_id){
 			$thumb_media_id=$thumb_file;
 		} else {
 			$result_obj = $this->uploadTmp($thumb_file,'image');
 			$thumb_media_id = $result_obj->media_id;
 		}
 		$msg_body = sprintf($this->_msg_template['music'],$title,$description,$music_url,$hq_music_url,$thumb_media_id);
 		$this->_msg($to,$from,'music',$msg_body);
 	}

 	private function _msgNews($to,$from,$item_list=array()){
 		//拼凑文章部分
 		$item_str = '';
 		foreach($item_list as $item){
 			$item_str .= sprintf($this->_msg_template['news_items'],$item['title'],$item['desc'],$item['picurl'],$item['url']);
 		}
 		//拼凑整体图文部分
 		$msg_body = sprintf($this->_msg_template['news'],count($item_list),$item_str);
 		$this->_msg($to,$from,'news',$msg_body);
 	}

 	/**
 	 * 被动响应POST或GET请求,只需要按要求格式返回数据(响应),即可。
 	 * @param  [type] $to       [description]
 	 * @param  [type] $from     [description]
 	 * @param  [type] $msg_type [description]
 	 * @param  [type] $msg_body [description]
 	 * @return [type]           [description]
 	 */
 	private function _msg($to,$from,$msg_type,$msg_body){
 		$response = sprintf($this->_msg_template['msg_basic'],$to,$from,time(),$msg_type,$msg_body);
 		$this->_log("[".$from."] response msg to [".$to."] msgContent= ".$response);
		die($response);
 	}

  	/**
 	 * 上传临时素材
 	 * @return resulb_obj [description]
 	 */
 	public function uploadTmp($file,$type){
 		$url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token='.$this->_getAccessToken().'&type='.$type;
 		$data = array(
 					'media'=>'@'.$file
 					 );
 		$result = $this->_requestPost($url,$data);
 		$result_obj = json_decode($result);
 		return $result_obj;
 	}

 	/**
 	 * 下载media文件
 	 * @param  string $media_id   media文件的media_id
 	 * @param  string $media_type 下载的媒体文件类型,image/voice/video
 	 * @param  string $file       指定保存在服务器的位置
 	 * @return [type]             [description]
 	 */
 	public function downloadMedia($media_id,$file=NULL,$media_type=''){
 		if($media_type=='video'){
 			$url='http';
 			$ssl=false;
 		}else{
 			$url='https';
 			$ssl=true;
 		}
 		$url .= '://api.weixin.qq.com/cgi-bin/media/get?access_token='.$this->_getAccessToken().'&media_id='.$media_id;
 		$result = $this->_requestGet($url,$ssl,true);
 		$this->_log('send request_Get to '.$url);
 
 		if($file){
 			file_put_contents($file,$result["body"]);
 		}elseif($media_type=='image'){
 			header($this->_getContentType($result["header"]));
 			echo $result["body"];
 		}
 	}

 	private function _create_file_name($request_xml){
 		$file='./received/'.$request_xml->FromUserName.substr(date('YmdHisv'),0,16).'.jpg';
 		return $file;
 	}

 	private function _get_http_header(){

 	}

 	/**
 	 * 用于第一次验证URL合法性
 	 */
 	public function firstValid(){
 		//检验签名的合法性
 		if($this->_checkSignature()){
 			//签名合法,告知微信公众平台服务器
 			echo $_GET['echostr'];
 		}
 	}

 	/**
 	 * 验证签名
 	 * @return bool [description]
 	 */
 	private function _checkSignature(){
 		//获得由微信公众平台请求的验证数据
 		$signature = $_GET['signature'];
 		$timestamp = $_GET['timestamp'];
 		$nonce = $_GET['nonce'];
 		//将时间戳,随机字符串,token按照字母顺序排列并连接
 		$tmp_arr = array($this->_token,$timestamp,$nonce);
 		sort($tmp_arr,SORT_STRING);//字典顺序

 		$tmp_str = implode($tmp_arr);//连接
 		$tmp_str = sha1($tmp_str);//sha1签名

 		if ($signature == $tmp_str){
 			return true;
 		} else {
 			return false;
 		}
 	}

 	/*
 	 * 获取 access_tonken
 	 * @param string $token_file 用来存储token的临时文件
 	 */
 	private function _getAccessToken($token_file='./access_token'){
 		// 考虑过期问题,将获取的access_token存储到某个文件中
 		$life_time=7200;
		if (file_exists($token_file)&&time()-filemtime($token_file)<$life_time){
			//存在有效的access_token
			return file_get_contents($token_file);
 		}
 		// 目标 URL:
 		$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->_appid}&secret={$this->_appsecret}";
 		// 向该URL,发送GET请求
 		$result=$this->_requestGet($url);
 		$this->_log($result);
 		if(!$result){
 			return false;
 		}
 		//存在返回响应结果
 		$result_obj=json_decode($result);
 		//写入
 		$this->_log('get access_token:'.$result_obj->access_token);
 		file_put_contents($token_file,$result_obj->access_token);
 		return $result_obj->access_token;
 	}

 	/**
 	 *[getQRCodeTicket description]
 	 *@param $content 内容
 	 *@param $type qr码类型
 	 *@param $expire 有效期,如果时临时的类型,则需要该参数
 	 *@return string ticket
 	 */
 	private function _getQRCodeTicket($content,$type=2,$expire=604800){
 		$access_token=$this->_getAccessToken();
		$url="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$access_token";
		$type_list = array(
			self::QRCODE_TYPE_TEMP => 'QR_SCENE',
			self::QRCODE_TYPE_LIMIT => 'QR_LIMIT_SCENE',
			self::QRCODE_TYPE_LIMIT_STR => 'QR_LIMIT_STR_SCENE'
			);
		$action_name=$type_list[$type];

		switch($type){
			case self::QRCODE_TYPE_TEMP:
			//{"expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}}
				$data_arr['expire_seconds']=$expire;
				$data_arr['action_name']=$action_name;
				$data_arr['action_info']['scene']['scene_id']=$content;
				break;
			case self::QRCODE_TYPE_LIMIT:
			//{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
				$data_arr['action_name']=$action_name;
				$data_arr['action_info']['scene']['scene_id']=$content;
				break;
			case self::QRCODE_TYPE_LIMIT_STR:
				$data_arr['action_name']=$action_name;
				$data_arr['action_info']['scene']['scene_str']=$content;
		}
		//$data='{"action_name":"'.$action_name.'","action_info":{"scene":{"scene_id":"'.$content.'"}}}';
		$data=json_encode($data_arr);
		$this->_log("send POST request:".$data);
		$result = $this->_requestPost($url,$data);

//		$this->_log('[apply QRCode ticket,get result]:'.$result);

		if(!$result){
			return false;
		}

		//处理相应数据
		$result_obj=json_decode($result);
		return $result_obj->ticket;
 	}


 	/**
 	 * getQRCode
 	 * @param  int/string  $content qrcode内容
 	 * @param  [type]  $file    存储为文件的地址,如果为NULL表示直接输出
 	 * @param  integer $type    类型,1(获取临时二维码,$content携带数字参数1-100000)
 	 *                                2 (获取永久二维码,$content携带数字参数)
 	 *                                3 (获取永久二维码,$content携带字符串参数)
 	 * @param  integer $expire  如果是临时,表示其有效期
 	 * @return [type]           [description]
 	 */
 	public function getQRCode($content,$file=NULL,$type=2,$expire=604800){
 		//获取ticket
 		$ticket=$this->_getQRCodeTicket($content,$type,$expire);
 //		$this->_log("[getQRCodeTicket]:".$ticket);
 		$url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=$ticket";
 		$result=$this->_requestGet($url); //此时result就是图像内容。
 		if($file){
 			file_put_contents($file,$result);
 		}else{
	  		header('Content-Type: image/jpg');
	 		echo $result;			
 		}
 	}
 	
 	private function _requestPost($url,$data,$ssl=true){
		//curl 完成
		$curl=curl_init();

		//设置curl选项
		curl_setopt($curl,CURLOPT_URL,$url);//URL

		//user_agent,请求代理信息
		$user_agent=isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36';
		curl_setopt($curl,CURLOPT_USERAGENT,$user_agent);

		//referer头,请求来源
		curl_setopt($curl,CURLOPT_AUTOREFERER,true);
		curl_setopt($curl,CURLOPT_TIMEOUT,20); //设置超时时间

		//SSL相关
		if($ssl){
			curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false); //终止从服务器端进行验证
			curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,2);//检查服务器SSL证书中是否存在一个公用名(common name)
		}
		//处理post相关选项
		curl_setopt($curl,CURLOPT_POST,true);  //是否为post请求
		curl_setopt($curl,CURLOPT_POSTFIELDS,$data); //数据处理
		//响应数据
		curl_setopt($curl,CURLOPT_HEADER,false); //是否处理响应头
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);//curl_exec()是否返回响应结果

		//发出请求
		$response=curl_exec($curl);
		if(false === $response){
			echo '<br>',curl_error($curl),'<br>';
			return false;
		}

		return $response;
 	}

 	/*
 	 *发送GET请求的方法 
 	 *@param string $url URL
 	 *@param bool $ssl 是否为https协议
 	 *@param book $header 返回是否包含http头。
 	 *@return string 响应主体Content,不包括http头
 	 */
 	private function _requestGet_0($url,$ssl=true,$header=false){
		//curl 完成
		$curl=curl_init();

		//设置curl选项
		curl_setopt($curl,CURLOPT_URL,$url);//URL

		//user_agent,请求代理信息
		$user_agent=isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36';
		curl_setopt($curl,CURLOPT_USERAGENT,$user_agent);

		//referer头,请求来源
		curl_setopt($curl,CURLOPT_AUTOREFERER,true);

		//SSL相关
		if($ssl){
			curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false); //终止从服务器端进行验证
			curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,2);//检查服务器SSL证书中是否存在一个公用名(common name)
		}

		//响应数据
		curl_setopt($curl,CURLOPT_HEADER,$header); //是否处理响应头,缺省是不处理
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);//curl_exec()是否返回响应结果


		//发出请求
		$response=curl_exec($curl);
		if(false === $response){
			echo '<br>',curl_error($curl),'<br>';
			return false;
		}
		return $response;
 	}


 	/**
	 *发送GET请求的方法
	 *@param string $url URL
	 *@param bool $ssl 是否为https协议
	 *@param book $header 返回是否包含http头。
	 *@return 如果定义返回头,这个返回值类型是字符串数组,下标分别为"header"携带http头信息,和"body"携带http内容信息。
	 *        如果定义不返回头,这个返回值类型是字符串,响应主体Content,不包括http头
	 */
	private function _requestGet($url,$ssl=true,$header=false){
		//curl 完成
		$curl=curl_init();

		//设置curl选项
		curl_setopt($curl,CURLOPT_URL,$url);//URL

		//user_agent,请求代理信息
		$user_agent=isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36';
		curl_setopt($curl,CURLOPT_USERAGENT,$user_agent);

		//referer头,请求来源
		curl_setopt($curl,CURLOPT_AUTOREFERER,true);

		//SSL相关
		if($ssl){
			curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false); //终止从服务器端进行验证
			curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,2);//检查服务器SSL证书中是否存在一个公用名(common name)
		}

		//响应数据
		curl_setopt($curl,CURLOPT_HEADER,$header); //是否处理(返回)响应头,缺省是不处理
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);//curl_exec()是否返回响应结果

		//发出请求
		$result=curl_exec($curl);
		if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == '200') {
			if ($header){
				$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
				$response=array(
							"header" => substr($result, 0, $headerSize),
							"body" => substr($result, $headerSize));
				return $response;
			} else {
				return $result;
			}
		}
		return false;

	}

	private function _getContentType($header){
		$this->_getHeaderLines($header);
		$pos_s=stripos($header,"Content-Type:");
		$sub_str=substr($header,$pos_s);
		$pos_s=stripos($sub_str," ");
		$pos_e=stripos($sub_str,"\r\n");
		$sub_str=substr($sub_str,0,$pos_e);
		return $sub_str;
	}

	private function _getHeaderLines($header){
		$head_line_list=array();

		$head_line_list=explode("\r\n",$header);
		return $head_line_list;
	} 

 	public function _log($log_content,$log_file='./res_msg_log.txt'){
 		file_put_contents($log_file,date('Y-m-d H:i:s',time())."==>  ".$log_content.PHP_EOL,FILE_APPEND);
 	}
}
?>

Creat By MiNi SheLL
Email: devilkiller@gmail.com