您好,欢迎访问一九零五行业门户网

官方微信接口(全接口 ) /微信摇一摇接口/微信支付接口

微信入口绑定,微信事件处理,微信api全部操作包含在这些文件中。
微信支付、微信红包、微信卡券、微信小店。
= 1 ){ curl_setopt($ch, curlopt_httpheader, $aheader); } curl_setopt($ch,curlopt_post, 1); curl_setopt($ch,curlopt_postfields,$vars); $data = curl_exec($ch); if($data){ curl_close($ch); return $data; } else { $error = curl_errno($ch); echo call faild, errorcode:$error\n; curl_close($ch); return false; } } /**************************************************** * 微信获取accesstoken 返回指定微信公众号的at信息 ****************************************************/ public function wxaccesstoken($appid = null , $appsecret = null){ $appid = is_null($appid) ? self::appid : $appid; $appsecret = is_null($appsecret) ? self::appsecret : $appsecret; $url = https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=.$appid.&secret=.$appsecret; $result = $this->wxhttpsrequest($url); //print_r($result); $jsoninfo = json_decode($result, true); $access_token = $jsoninfo[access_token]; return $access_token; } /**************************************************** * 微信获取apiticket 返回指定微信公众号的at信息 ****************************************************/ public function wxjsapiticket($appid = null , $appsecret = null){ $appid = is_null($appid) ? self::appid : $appid; $appsecret = is_null($appsecret) ? self::appsecret : $appsecret; $url = https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=.$this->wxaccesstoken(); $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); $ticket = $jsoninfo['ticket']; //echo $ticket .
; return $ticket; } public function wxverifyjsapiticket($appid = null , $appsecret = null){ if(!empty($this->jsapitime) && intval($this->jsapitime) > time() && !empty($this->jsapiticket)){ $ticket = $this->jsapiticket; } else{ $ticket = $this->wxjsapiticket($appid,$appsecret); $this->jsapiticket = $ticket; $this->jsapitime = time() + 7200; } return $ticket; } /**************************************************** * 微信通过openid获取用户信息,返回数组 ****************************************************/ public function wxgetuser($openid){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/user/info?access_token=.$wxaccesstoken.&openid=.$openid.&lang=zh_cn; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信生成二维码ticket ****************************************************/ public function wxqrcodeticket($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=.$wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); return $result; } /**************************************************** * 微信通过ticket生成二维码 ****************************************************/ public function wxqrcode($ticket){ $url = https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket= . urlencode($ticket); return $url; } /**************************************************** * 微信通过指定模板信息发送给指定用户,发送完成后返回指定json数据 ****************************************************/ public function wxsendtemplate($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=.$wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); return $result; } /**************************************************** * 发送自定义的模板消息 ****************************************************/ public function wxsetsend($touser, $template_id, $url, $data, $topcolor = '#7b68ee'){ $template = array( 'touser' => $touser, 'template_id' => $template_id, 'url' => $url, 'topcolor' => $topcolor, 'data' => $data ); $jsondata = urldecode(json_encode($template)); echo $jsondata; $result = $this->wxsendtemplate($jsondata); return $result; } /**************************************************** * 微信设置oauth跳转url,返回字符串信息 - scope = snsapi_base //验证时不返回确认页面,只能获取openid ****************************************************/ public function wxoauthbase($redirecturl,$state = ,$appid = null){ $appid = is_null($appid) ? self::appid : $appid; $url = https://open.weixin.qq.com/connect/oauth2/authorize?appid=.$appid.&redirect_uri=.$redirecturl.&response_type=code&scope=snsapi_base&state=.$state.#wechat_redirect; return $url; } /**************************************************** * 微信设置oauth跳转url,返回字符串信息 - scope = snsapi_userinfo //获取用户完整信息 ****************************************************/ public function wxoauthuserinfo($redirecturl,$state = ,$appid = null){ $appid = is_null($appid) ? self::appid : $appid; $url = https://open.weixin.qq.com/connect/oauth2/authorize?appid=.$appid.&redirect_uri=.$redirecturl.&response_type=code&scope=snsapi_userinfo&state=.$state.#wechat_redirect; return $url; } /**************************************************** * 微信oauth跳转指定url ****************************************************/ public function wxheader($url){ header(location:.$url); } /**************************************************** * 微信通过oauth返回页面中获取at信息 ****************************************************/ public function wxoauthaccesstoken($code,$appid = null , $appsecret = null){ $appid = is_null($appid) ? self::appid : $appid; $appsecret = is_null($appsecret) ? self::appsecret : $appsecret; $url = https://api.weixin.qq.com/sns/oauth2/access_token?appid=.$appid.&secret=.$appsecret.&code=.$code.&grant_type=authorization_code; $result = $this->wxhttpsrequest($url); //print_r($result); $jsoninfo = json_decode($result, true); //$access_token = $jsoninfo[access_token]; return $jsoninfo; } /**************************************************** * 微信通过oauth的access_token的信息获取当前用户信息 // 只执行在snsapi_userinfo模式运行 ****************************************************/ public function wxoauthuser($oauthat,$openid){ $url = https://api.weixin.qq.com/sns/userinfo?access_token=.$oauthat.&openid=.$openid.&lang=zh_cn; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 创建自定义菜单 ****************************************************/ public function wxmenucreate($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/menu/create?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 获取自定义菜单 ****************************************************/ public function wxmenuget(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/menu/get?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 删除自定义菜单 ****************************************************/ public function wxmenudelete(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/menu/delete?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 获取第三方自定义菜单 ****************************************************/ public function wxmenugetinfo(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服接口 - add 添加客服人员 ****************************************************/ public function wxserviceadd($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfaccount/add?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服接口 - update 编辑客服人员 ****************************************************/ public function wxserviceupdate($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfaccount/update?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服接口 - delete 删除客服人员 ****************************************************/ public function wxservicedelete($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfaccount/del?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信客服接口 - 上传头像 *******************************************************/ public function wxserviceupdatecover($kf_account, $media = '') { $wxaccesstoken = $this->wxaccesstoken(); //$data['access_token'] = $wxaccesstoken; $data['media'] = '@d:\\workspace\\htdocs\\yky_test\\logo.jpg'; $url = https:// api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=.$wxaccesstoken.&kf_account=.$kf_account; $result = $this->wxhttpsrequest($url,$data); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服接口 - 获取客服列表 ****************************************************/ public function wxservicelist(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服接口 - 获取在线客服接待信息 ****************************************************/ public function wxserviceonlinelist(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服接口 - 客服发送信息 ****************************************************/ public function wxservicesend($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服会话接口 - 创建会话 ****************************************************/ public function wxservicesessionadd($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfsession/create?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服会话接口 - 关闭会话 ****************************************************/ public function wxservicesessionclose(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfsession/close?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服会话接口 - 获取会话 ****************************************************/ public function wxservicesessionget($openid){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfsession/getsession?access_token=.$wxaccesstoken.&openid= . $openid; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服会话接口 - 获取会话列表 ****************************************************/ public function wxservicesessionlist($kf_account){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfsession/getsessionlist?access_token=.$wxaccesstoken.&kf_account= . $kf_account ; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信客服会话接口 - 未接入会话 ****************************************************/ public function wxservicesessionwaitcase(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token=.$wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 申请设备id ****************************************************/ public function wxdeviceapply($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/device/applyid?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 编辑设备id ****************************************************/ public function wxdeviceupdate($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/device/update?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 本店关联设备 ****************************************************/ public function wxdevicebindlocation($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/device/bindlocation?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 查询设备列表 ****************************************************/ public function wxdevicesearch($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/device/search?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 新增页面 ****************************************************/ public function wxpageadd($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/page/add?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 编辑页面 ****************************************************/ public function wxpageupdate($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/page/update?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 查询页面 ****************************************************/ public function wxpagesearch($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/page/search?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 删除页面 ****************************************************/ public function wxpagedelete($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/page/delete?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信摇一摇 - 上传图片素材 *******************************************************/ public function wxmaterialadd($media = '') { $wxaccesstoken = $this->wxaccesstoken(); //$data['access_token'] = $wxaccesstoken; $data['media'] = '@d:\\workspace\\htdocs\\yky_test\\logo.jpg'; $url = https://api.weixin.qq.com/shakearound/material/add?access_token=.$wxaccesstoken; $result = $this->wxhttpsrequest($url,$data); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 配置设备与页面的关联关系 ****************************************************/ public function wxdevicebindpage($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/device/bindpage?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 获取摇周边的设备及用户信息 ****************************************************/ public function wxgetshakeinfo($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /**************************************************** * 微信摇一摇 - 以设备为维度的数据统计接口 ****************************************************/ public function wxgetshakestatistics($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/shakearound/statistics/device?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /***************************************************** * 生成随机字符串 - 最长为32位字符串 *****************************************************/ public function wxnoncestr($length = 16, $type = false) { $chars = abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789; $str = ; for ($i = 0; $i parameters = $parameters; return $this->parameters; } else{ return array(); } } /******************************************************* * 微信格式化数组变成参数格式 - 支持url加密 *******************************************************/ public function wxformatarray($parameters = null, $urlencode = false){ if(is_null($parameters)){ $parameters = $this->parameters; } $restr = ;//初始化空 ksort($parameters);//排序参数 foreach ($parameters as $k => $v){//循环定制参数 if (null != $v && null != $v && sign != $k) { if($urlencode){//如果参数需要增加url加密就增加,不需要则不需要 $v = urlencode($v); } $restr .= $k . = . $v . &;//返回完整字符串 } } if (strlen($restr) > 0) {//如果存在数据则将最后“&”删除 $restr = substr($restr, 0, strlen($restr)-1); } return $restr;//返回字符串 } /******************************************************* * 微信md5签名生成器 - 需要将参数数组转化成为字符串[wxformatarray方法] *******************************************************/ public function wxmd5sign($content, $privatekey){ try { if (is_null($privatekey)) { throw new exception(财付通签名key不能为空!); } if (is_null($content)) { throw new exception(财付通签名内容不能为空); } $signstr = $content . &key= . $privatekey; return strtoupper(md5($signstr)); } catch (exception $e) { die($e->getmessage()); } } /******************************************************* * 微信sha1签名生成器 - 需要将参数数组转化成为字符串[wxformatarray方法] *******************************************************/ public function wxsha1sign($content){ try { if (is_null($content)) { throw new exception(签名内容不能为空); } //$signstr = $content; return sha1($content); } catch (exception $e) { die($e->getmessage()); } } /******************************************************* * 微信jsapi整合方法 - 通过调用此方法获得jsapi数据 *******************************************************/ public function wxjsapipackage(){ $jsapi_ticket = $this->wxverifyjsapiticket(); // 注意 url 一定要动态获取,不能 hardcode. $protocol = (!empty($_server['https']) && $_server['https'] !== 'off' || $_server['server_port'] == 443) ? https:// : http://; $url = $protocol.$_server[http_host].$_server[request_uri]; $timestamp = time(); $noncestr = $this->wxnoncestr(); $signpackage = array( jsapi_ticket => $jsapi_ticket, noncestr => $noncestr, timestamp => $timestamp, url => $url ); // 这里参数的顺序要按照 key 值 ascii 码升序排序 $rawstring = jsapi_ticket=$jsapi_ticket&noncestr=$noncestr×tamp=$timestamp&url=$url; //$rawstring = $this->wxformatarray($signpackage); $signature = $this->wxsha1sign($rawstring); $signpackage['signature'] = $signature; $signpackage['rawstring'] = $rawstring; $signpackage['appid'] = self::appid; return $signpackage; } /******************************************************* * 微信卡券:jsapi 卡券package - 基础参数没有附带任何值 - 再生产环境中需要根据实际情况进行修改 *******************************************************/ public function wxcardpackage($cardid , $timestamp = ''){ $api_ticket = $this->wxverifyjsapiticket(); if(!empty($timestamp)){ $timestamp = $timestamp; } else{ $timestamp = time(); } $arrays = array(self::appsecret,$timestamp,$cardid); sort($arrays , sort_string); //print_r($arrays); //echo implode(,$arrays).
; $string = sha1(implode($arrays)); //echo $string; $resultarray['cardid'] = $cardid; $resultarray['cardext'] = array(); $resultarray['cardext']['code'] = ''; $resultarray['cardext']['openid'] = ''; $resultarray['cardext']['timestamp'] = $timestamp; $resultarray['cardext']['signature'] = $string; //print_r($resultarray); return $resultarray; } /******************************************************* * 微信卡券:jsapi 卡券全部卡券 package *******************************************************/ public function wxcardallpackage($cardidarray = array(),$timestamp = ''){ $rearrays = array(); if(!empty($cardidarray) && (is_array($cardidarray) || is_object($cardidarray))){ //print_r($cardidarray); foreach($cardidarray as $value){ //print_r($this->wxcardpackage($value,$openid)); $rearrays[] = $this->wxcardpackage($value,$timestamp); } //print_r($rearrays); } else{ $rearrays[] = $this->wxcardpackage($cardidarray,$timestamp); } return strval(json_encode($rearrays)); } /******************************************************* * 微信卡券:获取卡券列表 *******************************************************/ public function wxcardlistpackage($cardtype = , $cardid = ){ //$api_ticket = $this->wxverifyjsapiticket(); $resultarray = array(); $timestamp = time(); $noncestr = $this->wxnoncestr(); //$strings = $arrays = array(self::appid,self::appsecret,$timestamp,$noncestr); sort($arrays , sort_string); $string = sha1(implode($arrays)); $resultarray['app_id'] = self::appid; $resultarray['card_sign'] = $string; $resultarray['time_stamp'] = $timestamp; $resultarray['nonce_str'] = $noncestr; $resultarray['card_type'] = $cardtype; $resultarray['card_id'] = $cardid; return $resultarray; } /******************************************************* * 将数组解析xml - 微信红包接口 *******************************************************/ public function wxarraytoxml($parameters = null){ if(is_null($parameters)){ $parameters = $this->parameters; } if(!is_array($parameters) || empty($parameters)){ die(参数不为数组无法解析); } $xml = ; foreach ($arr as $key=>$val) { if (is_numeric($val)) { $xml.=.$val.; } else $xml.=; } $xml.=; return $xml; } /******************************************************* * 微信卡券:上传logo - 需要改写动态功能 *******************************************************/ public function wxcardupdateimg() { $wxaccesstoken = $this->wxaccesstoken(); //$data['access_token'] = $wxaccesstoken; $data['buffer'] = '@d:\\workspace\\htdocs\\yky_test\\logo.jpg'; $url = https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=.$wxaccesstoken; $result = $this->wxhttpsrequest($url,$data); $jsoninfo = json_decode($result, true); return $jsoninfo; //array(1) { [url]=> string(121) http://mmbiz.qpic.cn/mmbiz/ibuyxphqexepntw4atkyias1cf3ztkiars9pfpzf1k5icvxd7xw0kxuaxhdzkepd9miccmcn0dctjfw6tnm93miaafrq/0 } } /******************************************************* * 微信卡券:获取颜色 *******************************************************/ public function wxcardcolor(){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/getcolors?access_token=.$wxaccesstoken; $result = $this->wxhttpsrequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:拉取门店列表 *******************************************************/ public function wxbatchget($offset = 0, $count = 0){ $jsondata = json_encode(array('offset' => intval($offset) , 'count' => intval($count))); $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/location/batchget?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:创建卡券 *******************************************************/ public function wxcardcreated($jsondata) { $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/create?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:查询卡券详情 *******************************************************/ public function wxcardgetinfo($jsondata) { $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/get?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:设置白名单 *******************************************************/ public function wxcardwhitelist($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/testwhitelist/set?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:消耗卡券 *******************************************************/ public function wxcardconsume($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/code/consume?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:删除卡券 *******************************************************/ public function wxcarddelete($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/delete?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:选择卡券 - 解析code *******************************************************/ public function wxcarddecryptcode($jsondata){ $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/code/decrypt?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:更改库存 *******************************************************/ public function wxcardmodifystock($cardid , $increase_stock_value = 0 , $reduce_stock_value = 0){ if(intval($increase_stock_value) == 0 && intval($reduce_stock_value) == 0){ return false; } $jsondata = json_encode(array(card_id => $cardid , 'increase_stock_value' => intval($increase_stock_value) , 'reduce_stock_value' => intval($reduce_stock_value))); $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/modifystock?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:查询用户code *******************************************************/ public function wxcardquerycode($code , $cardid = ''){ $jsondata = json_encode(array(code => $code , 'card_id' => $cardid )); $wxaccesstoken = $this->wxaccesstoken(); $url = https://api.weixin.qq.com/card/code/get?access_token= . $wxaccesstoken; $result = $this->wxhttpsrequest($url,$jsondata); $jsoninfo = json_decode($result, true); return $jsoninfo; } }
wxoauthaccesstoken($code); //print_r($info); $openid = $info['openid']; } $signpackage = $wx->wxjsapipackage(); ?> jsapi接口测试

token = $token; } public function wcchecksignature(){ try{ if (empty($this->token)) { throw new exception('token is not defined!'); } $signature = $_get[signature]; $timestamp = $_get[timestamp]; $nonce = $_get[nonce]; $token = $this->token; $tmparr = array($token, $timestamp, $nonce); // use sort_string rule sort($tmparr, sort_string); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } } catch (exception $e) { echo 'message: ' .$e->getmessage(); } } public function wcvalid(){ $echostr = isset($_get[echostr]) && !empty($_get[echostr]) ? addslashes($_get[echostr]) : null; if(is_null($echostr)){ $this->wcmsg(); } else{ //valid signature , option if($this->wcchecksignature()){ echo $echostr; exit; } else{ exit(); } } } public function wcmsg(){ //get post data, may be due to the different environments $poststr = isset($globals[http_raw_post_data]) && !empty($globals[http_raw_post_data]) ? $globals[http_raw_post_data] : ; if(!empty($poststr)){ libxml_disable_entity_loader(true); $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $this->zclog(true,$postobj); $fromusername = $postobj->fromusername; $tousername = $postobj->tousername; $msgtype = $postobj->msgtype; if($msgtype == 'event'){//执行事件相应 $event = $postobj->event; switch ($event) { case 'subscribe'://关注 break; case 'unsubscribe'://取消关注 break; case 'scan'://扫描 break; case 'location'://地址 break; case 'click'://点击时间 break; case 'view'://跳转 break; case 'card_pass_check'://卡券审核通过 break; case 'card_not_pass_check'://卡券审核失败 break; case 'user_get_card'://用户领取卡券 break; case 'user_del_card'://用户删除卡券 break; case 'user_view_card'://用户浏览会员卡 break; case 'user_consume_card'://用户核销卡券 break; case 'kf_create_session'://创建会话 break; case 'kf_close_session'://关闭会话 break; case 'kf_switch_session'://转接会话 break; default: break; } } else{ switch ($msgtype) { case 'text'://文本格式 break; case 'image'://图片格式 break; case 'voice'://声音 break; case 'video'://视频 break; case 'shortvideo'://小视频 break; case 'location'://上传地理位置 break; case 'link'://链接相应 break; default: break; } } //////////////////////////////////////////////////////////////////// $keyword = trim($postobj->content); $time = time(); $texttpl = %s 0 ; if(!empty( $keyword )){ $msgtype = text; $contentstr = welcome to wechat world!; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; } else{ echo input something...; } //////////////////////////////////////////////////////////////////// } else{ echo 暂时没有任何信息!; exit; } } //日志log public function zclog($errcode , $errmsg){ $this->returnay = array(); $this->returnay['errcode'] = $errcode; $this->returnay['errmsg'] = $errmsg; $this->returnay['errtime'] = date(y-m-d h:i:s,time()); $logfile = fopen(logfile_.date(ymd,time())..txt, a+); $txt = json_encode($this->returnay).\n; fwrite($logfile, $txt); fclose($logfile); //return $this->returnay; } }
其它类似信息

推荐信息