Overview

Packages

  • None
  • WxRobot
    • Admin
    • Cmd
    • CoreFunctions
    • Exends
    • Install
    • Table
    • Uninstall
    • WxSDK

Classes

  • ErrorCode
  • PKCS7Encoder
  • Prpcrypt
  • SHA1
  • Weixin_BaseCore
  • WeiXin_SDK
  • Weixin_Template
  • WXBizMsgCrypt
  • WxRobot_Admin
  • WxRobot_Admin_Menu_Extends
  • WxRobot_Admin_Menu_Instro
  • WxRobot_Admin_Menu_Menu
  • WxRobot_Admin_Menu_Records
  • WxRobot_Admin_Menu_Reply
  • WxRobot_Admin_Menu_Setting
  • WxRobot_Admin_Menu_Statistics
  • WxRobot_Cmd
  • WxRobot_Cmd_Event
  • WxRobot_Cmd_Event_User
  • WxRobot_Cmd_Text
  • WxRobot_Extends
  • WxRobot_Install
  • WxRobot_Robot
  • WxRobot_SDK
  • WxRobot_Table_Extends
  • WxRobot_Table_Menu
  • WxRobot_Table_Records
  • WxRobot_Table_Reply
  • WxRobot_Uninstall
  • WxRobot_Wp
  • XMLParse

Functions

  • wx_admin_log
  • wx_is_xml
  • wx_notice_msg
  • wx_parse_xml
  • wx_random_big_pic
  • wx_random_small_pic
  • wx_request_array
  • wx_request_decode
  • wx_request_is_encode
  • wx_request_xml
  • wx_send_encode
  • Overview
  • Package
  • Class
  1: <?php
  2: /**
  3:  * 微信SDK
  4:  *
  5:  * @author      midoks
  6:  * @category    WxSDK
  7:  * @package     
  8:  */
  9: 
 10: define('WEIXIN_SDK', str_replace('\\', '/', dirname(__FILE__)).'/');
 11: defined('WEIXIN_DEBUG') or define('WEIXIN_DEBUG', true);//默认关闭
 12: 
 13: class WeiXin_SDK{
 14: 
 15:     public $template;
 16:     public $base;
 17:     public $app_id;
 18:     public $app_sercet;
 19: 
 20:     /**
 21:      * WxRobot_SDK Instance
 22:      */
 23:     public static $_instance = null;
 24: 
 25: 
 26:     /**
 27:      * WxRobot SDK类实例化
 28:      * 
 29:      * @return WxRobot_SDK instance
 30:      */
 31:     public static function instance(){
 32:         if( is_null (self::$_instance)){
 33:             self::$_instance = new self();
 34:         }
 35:         return self::$_instance;
 36:     }
 37: 
 38: 
 39:     //构造函数
 40:     public function __construct($AppId='', $AppSecret=''){
 41: 
 42:         $this->app_id = $AppId;
 43:         $this->app_sercet = $AppSecret;
 44: 
 45:         include_once(WEIXIN_SDK.'libs/base.class.php');
 46:         include_once(WEIXIN_SDK.'libs/template.class.php');
 47: 
 48:         $this->template = new Weixin_Template();
 49:         $this->base = new Weixin_BaseCore();
 50:     }
 51: 
 52: //no appkey and appsercet
 53: 
 54:     // response message (text)  
 55:     public function toMsgText($fromUserName, $toUserName, $Msg){
 56:         return $this->template->toMsgText($fromUserName, $toUserName, $Msg);
 57:     }
 58: 
 59:     // response message (image) 
 60:     public function toMsgImage($fromUserName, $toUserName, $MediaId){
 61:         return $this->template->toMsgImage($fromUserName, $toUserName, $MediaId);
 62:     }
 63: 
 64:     // response message (voice) 
 65:     public function toMsgVoice($fromUserName, $toUserName, $MediaId){
 66:         return $this->template->toMsgVoice($fromUserName, $toUserName, $MediaId);
 67:     }
 68: 
 69:     // response message (music) 
 70:     public function toMsgMusic($fromUserName, $toUserName, $Title, $Description, $MusicUrl, $HQMusicUrl, $ThumbMediaId=''){
 71:         if(empty($ThumbMediaId)){
 72:             return $this->template->toMsgMusic($fromUserName, $toUserName, $Title, $Description, $MusicUrl, $HQMusicUrl, $ThumbMediaId);
 73:         }else{
 74:             return $this->template->toMsgMusicId($fromUserName, $toUserName, $Title, $Description, $MusicUrl, $HQMusicUrl, $ThumbMediaId);
 75:         }
 76:     }
 77: 
 78:     // response message (video) 
 79:     public function toMsgVideo($fromUserName, $toUserName, $MediaId, $Title, $Description){
 80:         return $this->template->toMsgVideo($toUserName, $fromUserName, $MediaId, $Title, $Description);
 81:     }
 82: 
 83:     // response message (news)  
 84:     public function toMsgNews($fromUserName, $toUserName, $News){
 85:             return $this->template->toMsgNews($fromUserName, $toUserName, $News);
 86:     }
 87: //END TO MSG
 88: 
 89: 
 90: //have appkey and appsercet
 91:     /**
 92:      *  get token
 93:      *  @ret json
 94:      */
 95:     public function getToken(){
 96:         $app_id = $this->app_id;
 97:         $app_sercet = $this->app_sercet;
 98:         return $this->base->getToken($app_id, $app_sercet);
 99:     }
100: 
101:     public function pushMsgText($token, $open_id, $msg){
102:         return $this->base->pushMsgText($token, $open_id, $msg);
103:     }
104: 
105:     public function pushMsgImage($token, $open_id, $media_id){
106:         return $this->base->pushMsgImage($token, $open_id, $media_id);
107:     }
108: 
109:     public function pushMsgImageAdv($token, $open_id, $file){
110:         $ret = $this->upload($token, 'image', $file);
111:         if(!$ret){
112:             return '{errcode: "network imeout"}';
113:         }
114:         $data = json_decode($ret, true);
115:         if(isset($data['errcode'])){
116:             return $ret;
117:         }
118:         $ret = $this->pushMsgImage($token, $open_id, $data['media_id']);
119:         return $ret;
120:     }
121: 
122:     public function pushMsgVoice($token, $open_id, $media_id){
123:         return $this->base->pushMsgVoice($token, $open_id, $media_id);
124:     }
125: 
126:     public function pushMsgVoiceAdv($token, $open_id, $file){
127:         $ret = $this->upload($token, 'voice', $file);
128:         if(!$ret){
129:             return '{errcode: "network imeout"}';
130:         }
131:         $data = json_decode($ret, true);
132:         if(isset($data['errcode'])){
133:             return $ret;
134:         }
135:         $ret = $this->pushMsgVoiceAdv($token, $open_id, $data['media_id']);
136:         return $ret;
137:     }
138: 
139:     public function pushMsgVideo($token, $open_id, $media_id, $title, $desc){
140:         return $this->base->pushMsgVoice($token, $open_id, $media_id, $title, $desc);
141:     }
142: 
143:     public function pushMsgVideoAdv($token, $open_id, $file, $title, $desc){
144:         $ret = $this->upload($token, 'voice', $file);
145:         if(!$ret){
146:             return '{errcode: "network imeout"}';
147:         }
148:         $data = json_decode($ret, true);
149:         if(isset($data['errcode'])){
150:             return $ret;
151:         }
152:         $ret = $this->pushMsgVoice($token, $open_id, $data['media_id'], $title, $desc);
153:         return $ret;
154:     }
155: 
156:     public function pushMsgMusic($token, $open_id, $thumb_media_id, $title, $desc, $musicurl, $hqmusicurl){
157:         return $this->base->pushMsgMusic($token, $open_id, $thumb_media_id, $title, $desc, $musicurl, $hqmusicurl);
158:     }
159: 
160:     public function pushMsgMusicAdv($token, $open_id, $file, $title, $desc, $musicurl, $hqmusicurl){
161:         $ret = $this->upload($token, 'voice', $file);
162:         if(!$ret){
163:             return '{errcode: "network imeout"}';
164:         }
165:         $data = json_decode($ret, true);
166:         if(isset($data['errcode'])){
167:             return $ret;
168:         }
169:         $ret = $this->pushMsgVoice($token, $open_id, $data['media_id'], $title, $desc, $musicurl, $hqmusicurl);
170:         return $ret;
171:     }
172: 
173:     /**
174:      * @exp: $info should be:
175:      *      $info[]["title"] = "Happy Day";
176:      *      $info[]["description"]="Is Really A Happy Day";
177:      *      $info[]["url"] = "URL";
178:      *      $info[]["picurl"] = "PIC_URL";
179:      */
180:     public function pushMsgNews($token, $open_id, $info){
181:         return $this->base->pushMsgNews($token, $open_id, $info);
182:     }
183: ///END PUSH
184: 
185: 
186: 
187: /**
188:  *  多客服系统接口 start 
189:  *  多客服系统是在的插件中使用!!!
190:  */
191:     
192:     /**
193:      *  @func 获取客服聊天记录
194:      *  @param $token       调用接口凭证
195:      *  @param $open_id     普通用户的标识,对当前公众号唯一
196:      *  @param $starttime   查询开始时间,UNIX时间戳
197:      *  @param $endtime     查询结束时间,UNIX时间戳,每次查询不能跨日查询
198:      *  @param $pagesize    每页大小,每页最多拉取1000条
199:      *  @param $pageindex   查询第几页,从1开始     
200:      */
201:     public function getCustomServiceLog($token, $open_id, $starttime, $endtime, $pagesize=20, $pageindex=1){
202:         return $this->base->getCustomServiceLog($token, $open_id, $starttime, $endtime, $pagesize, $pageindex);
203:     }
204: /* 多客服系统接口 end */
205: 
206: 
207: //END PUSH ADV
208: 
209:     //menu setting
210:     public function menuGet($token){
211:         return $this->base->menuGet($token);
212:     }
213: 
214:     public function menuSet($token, $json){
215:         return $this->base->menuSet($token, $json);
216:     }
217: 
218:     public function menuDel($token){
219:         return $this->base->menuDel($token);
220:     }
221: 
222: //
223: 
224: //智能接口
225: 
226:     //智能接口分析
227:     public function getSemantic($token, $query, $category, $lat, $long, $city, $region, $appid, $uid){
228:         return $this->base->getSemantic($token, $query, $category, $lat, $long, $city, $region, $appid, $uid);
229:     }
230: 
231: //uplaod and download
232: 
233:     public function download($token, $media_id){
234:         return $this->base->download($token, $media_id);
235:     }
236: 
237:     public function upload($token, $type, $file){
238:         if(in_array($type, array('image', 'voice', 'video', 'thumb'))){
239:             return $this->base->upload($token, $type, $file);
240:         }else{
241:             return $this->notice('upload: invalid media type', __LINE__);
242:         }   
243:     }
244: 
245:     public function uploadUrl($token, $type, $fn, $mime, $content){
246:         if(in_array($type, array('image', 'voice', 'video', 'thumb'))){
247:             return $this->base->uploadUrl($token, $type, $fn, $mime, $content);
248:         }else{
249:             return $this->notice('upload: invalid media type', __LINE__);
250:         }
251:     }
252: 
253: //user info 
254:     public function getUserInfo($token, $open_id, $lang='zh_CN'){
255:         return $this->base->getUserInfo($token, $open_id, $lang);
256:     }
257: 
258:     public function getUserList($token, $next_openid){
259:         return $this->base->getUserList($token, $next_openid);
260:     }
261: 
262:     public function setUserGroup($token, $json){
263:         return $this->base->setUserGroup($token, $json);
264:     }
265: 
266:     public function getUserGroup($token){
267:         return $this->base->getUserGroup($token);
268:     }
269: 
270:     public function getUserGroupPosition($token, $json){
271:         return $this->base->getUserGroupPosition($token, $json);
272:     }
273: 
274:     public function modUserGroup($token, $json){
275:         return $this->base->modUserGroup($token, $json);
276:     }
277: 
278:     public function movUserGroup($token, $json){
279:         return $this->base->movUserGroup($token, $json);
280:     }
281: 
282:     public function updateRemark($token, $open_id, $remark){
283:         return $this->base->updateRemark($token, $open_id, $remark);
284:     }
285: 
286: //推送消息
287: 
288: /* 推广相关 start */
289: 
290:     //创建二维码ticket
291:     public function temp_ticket($token, $json){
292:         return $this->base->temp_ticket($token, $json); 
293:     }
294: 
295:     //创建永久二维码ticket
296:     public function permanent_ticket($token, $json){
297:         return $this->base->permanent_ticket($token, $json);
298:     }
299: 
300:     //返回路径
301:     public function get_ticket($ticket){
302:         return $this->base->get_ticket($ticket);
303:     }
304: 
305:     //把长连接转换为短链接
306:     public function long2short($token, $url){
307:         return $this->base->long2short($token, $url);
308:     }
309: 
310: 
311: /* 推广相关 end */
312:     
313:     //上传图文消息素材  
314:     public function uploadMsgImageText($token, $msg){
315:         return $this->base->uploadMsgImageText($token, $msg);
316:     }
317: 
318:     //通过分组进行群发
319:     public function sendAllByGroup($token, $group_id, $media_id, $msgtype){
320:         return $this->base->sendAllByGroup($token, $group_id, $media_id, $msgtype);
321:     }
322: 
323:     //根据OpenID列表群发
324:     public function sendAll($token, $user, $media_id, $msgtype){
325:         return $this->base->sendAll($token, $user, $media_id, $msgtype);
326:     }
327: 
328:     //删除群发信息
329:     public function deleteSend($token, $id){
330:         return $this->base->deleteSend($token, $id);
331:     }
332: 
333:     //发送模版消息
334:     public function sendTemplateInfo($token, $json){
335:         return $this->base->sendTemplateInfo($token, $json);
336:     }
337: 
338:     //获取微信地址
339:     public function getWeixinIp($token){
340:         return $this->base->getWeixinIp($token);
341:     }
342: 
343:     //处理后的JSON
344:     public function to_json($arr){
345:         return $this->base->to_json($arr);
346:     }
347: 
348:     //提示
349:     public function notice($msg, $line){
350:         if(WEIXIN_DEBUG){
351:             $this->logs($msg, $line);
352:         }else{
353:             trigger_error($msg);
354:         }
355:         return $msg;
356:     }
357: 
358:     public function logs($msg, $line){
359:         $fn = WEIXIN_SDK.'logs/'.date('Y-m-d').'.log';
360:         $handler = fopen($fn, 'a');
361:         fwrite($handler, 'error: in '.__FILE__.' at '.$line.' line '.$msg."\t".date('Y-m-d H:i:s')."\r\n");
362:         fclose($handler);
363:     }
364: }
365: ?>
366: 
API documentation generated by ApiGen