浏览代码

1、添加 语义理解接口 (暂时官方未开放使用权限)
2、修复 媒体下载接口getMedia() 返回内容错误问题

binsee 10 年之前
父节点
当前提交
5c753b04b2
共有 5 个文件被更改,包括 113 次插入5 次删除
  1. 3 1
      README.md
  2. 43 1
      Thinkphp/Wechat.class.php
  3. 20 1
      errCode.php
  4. 44 1
      wechat.class.php
  5. 3 1
      wiki/官方API类库.md

+ 3 - 1
README.md

@@ -49,6 +49,7 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
 - 发货通知 (支付权限) 
 - 支付订单查询 (支付权限) 
 - 模板消息(支付权限) 
+- 语义理解(暂未开放) 
 
 
 ### 初始化动作 
@@ -68,7 +69,7 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
 
 ### 新增Auth高级权限类方法:   
  *  checkAuth($appid,$appsecret,$token) 此处传入公众后台高级接口提供的appid和appsecret, 或者手动指定$token为access_token。函数将返回access_token操作令牌
- *  createMenu($data) 创建菜单 $data菜单结构详见 http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3 
+ *  createMenu($data) 创建菜单 $data菜单结构详见 **[自定义菜单创建接口](http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口)**
  *  getMenu() 获取菜单 
  *  deleteMenu() 删除菜单 
  *  uploadMedia($data, $type) 上传多媒体文件
@@ -107,6 +108,7 @@ https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/course2_tmpl&lang=zh_CN
  *  transfer_customer_service($customer_account) 转发多客服消息
  *  getCustomServiceKFlist() 获取多客服客服基本信息
  *  getCustomServiceOnlineKFlist() 获取多客服在线客服接待信息
+ *  querySemantic($uid,$query,$category,$latitude=0,$longitude=0,$city="",$region="") 语义理解接口 参数含义及返回的json内容请查看 **[微信语义理解接口](http://mp.weixin.qq.com/wiki/index.php?title=语义理解)**
  
  
 ## 2. wechatext.class.php 非官方扩展API  

+ 43 - 1
Thinkphp/Wechat.class.php

@@ -93,6 +93,7 @@ class Wechat
 	const CUSTOM_SERVICE_GET_RECORD = '/customservice/getrecord?';
 	const CUSTOM_SERVICE_GET_KFLIST = '/customservice/getkflist?';
 	const CUSTOM_SERVICE_GET_ONLINEKFLIST = '/customservice/getkflist?';
+	const SEMANTIC_API_URL= 'https://api.weixin.qq.com/semantic/semproxy/search?';
 	
 	private $token;
 	private $appid;
@@ -1079,7 +1080,7 @@ class Wechat
 				$this->errMsg = $json['errmsg'];
 				return false;
 			}
-			return $json;
+			return $result;
 		}
 		return false;
 	}
@@ -1903,4 +1904,45 @@ class Wechat
 		}
 		return false;
 	}
+	
+	/**
+	 * 语义理解接口
+	 * @param String $uid      用户唯一id(非开发者id),用户区分公众号下的不同用户(建议填入用户openid)
+	 * @param String $query    输入文本串
+	 * @param String $category 需要使用的服务类型,多个用“,”隔开,不能为空
+	 * @param Float $latitude  纬度坐标,与经度同时传入;与城市二选一传入
+	 * @param Float $longitude 经度坐标,与纬度同时传入;与城市二选一传入
+	 * @param String $city     城市名称,与经纬度二选一传入
+	 * @param String $region   区域名称,在城市存在的情况下可省略;与经纬度二选一传入
+	 * @return boolean|array
+	 */
+	public function querySemantic($uid,$query,$category,$latitude=0,$longitude=0,$city="",$region=""){
+	    if (!$this->access_token && !$this->checkAuth()) return false;
+	    $data=array(
+	            'query' => $query,
+	            'category' => $category,
+	            'appid' => $this->appid,
+	            'uid' => ''
+	    );
+	    //地理坐标或城市名称二选一
+	    if (isset($latitude)) {
+	        $data['latitude'] = $latitude;
+	        $data['longitude'] = $longitude;
+	    } elseif (isset($city)) {
+	        $data['city'] = $city;
+	        $data['region'] = $region;
+	    }
+	    $result = $this->http_post(self::SEMANTIC_API_URL.'access_token='.$this->access_token,self::json_encode($data));
+	    if ($result)
+	    {
+	        $json = json_decode($result,true);
+	        if (!$json || !empty($json['errcode'])) {
+	            $this->errCode = $json['errcode'];
+	            $this->errMsg = $json['errmsg'];
+	            return false;
+	        }
+	        return $json;
+	    }
+	    return false;
+	}
 }

+ 20 - 1
errCode.php

@@ -32,7 +32,7 @@ class ErrCode
 	    '40014'=>'不合法的access_token',
 	    '40015'=>'不合法的菜单类型',
 	    '40016'=>'不合法的按钮个数',
-	    '40017'=>'不合法的按钮个数',
+	    '40017'=>'不合法的按钮类型',
 	    '40018'=>'不合法的按钮名字长度',
 	    '40019'=>'不合法的按钮KEY长度',
 	    '40020'=>'不合法的按钮URL长度',
@@ -96,6 +96,25 @@ class ErrCode
 	    '47001'=>'解析JSON/XML内容错误',
 	    '48001'=>'api功能未授权',
 	    '50001'=>'用户未授权该api',
+	        '7000000'=>'请求正常,无语义结果',
+	        '7000001'=>'缺失请求参数',
+	        '7000002'=>'signature 参数无效',
+	        '7000003'=>'地理位置相关配置 1 无效',
+	        '7000004'=>'地理位置相关配置 2 无效',
+	        '7000005'=>'请求地理位置信息失败',
+	        '7000006'=>'地理位置结果解析失败',
+	        '7000007'=>'内部初始化失败',
+	        '7000008'=>'非法 appid(获取密钥失败)',
+	        '7000009'=>'请求语义服务失败',
+	        '7000010'=>'非法 post 请求',
+	        '7000011'=>'post 请求 json 字段无效',
+	        '7000030'=>'查询 query 太短',
+	        '7000031'=>'查询 query 太长',
+	        '7000032'=>'城市、经纬度信息缺失',
+	        '7000033'=>'query 请求语义处理失败',
+	        '7000034'=>'获取天气信息失败',
+	        '7000035'=>'获取股票信息失败',
+	        '7000036'=>'utf8 编码转换失败',
 	);
 	
 	public static function getErrText($err) {

+ 44 - 1
wechat.class.php

@@ -93,6 +93,7 @@ class Wechat
 	const CUSTOM_SERVICE_GET_RECORD = '/customservice/getrecord?';
 	const CUSTOM_SERVICE_GET_KFLIST = '/customservice/getkflist?';
 	const CUSTOM_SERVICE_GET_ONLINEKFLIST = '/customservice/getkflist?';
+	const SEMANTIC_API_URL= 'https://api.weixin.qq.com/semantic/semproxy/search?';
 	
 	private $token;
 	private $appid;
@@ -1071,7 +1072,7 @@ class Wechat
 				$this->errMsg = $json['errmsg'];
 				return false;
 			}
-			return $json;
+			return $result;
 		}
 		return false;
 	}
@@ -1895,4 +1896,46 @@ class Wechat
 		}
 		return false;
 	}
+	
+	/**
+	 * 语义理解接口
+	 * @param String $uid      用户唯一id(非开发者id),用户区分公众号下的不同用户(建议填入用户openid)
+	 * @param String $query    输入文本串
+	 * @param String $category 需要使用的服务类型,多个用“,”隔开,不能为空
+	 * @param Float $latitude  纬度坐标,与经度同时传入;与城市二选一传入
+	 * @param Float $longitude 经度坐标,与纬度同时传入;与城市二选一传入
+	 * @param String $city     城市名称,与经纬度二选一传入
+	 * @param String $region   区域名称,在城市存在的情况下可省略;与经纬度二选一传入
+	 * @return boolean|array
+	 */
+	public function querySemantic($uid,$query,$category,$latitude=0,$longitude=0,$city="",$region=""){
+	    if (!$this->access_token && !$this->checkAuth()) return false;
+	    $data=array(
+	            'query' => $query,
+	            'category' => $category,
+	            'appid' => $this->appid,
+	            'uid' => ''
+	    );
+	    //地理坐标或城市名称二选一
+	    if ($latitude) {
+	        $data['latitude'] = $latitude;
+	        $data['longitude'] = $longitude;
+	    } elseif ($city) {
+	        $data['city'] = $city;
+	    } elseif ($region) {
+	        $data['region'] = $region;
+	    }
+	    $result = $this->http_post(self::SEMANTIC_API_URL.'access_token='.$this->access_token,self::json_encode($data));
+	    if ($result)
+	    {
+	        $json = json_decode($result,true);
+	        if (!$json || !empty($json['errcode'])) {
+	            $this->errCode = $json['errcode'];
+	            $this->errMsg = $json['errmsg'];
+	            return false;
+	        }
+	        return $json;
+	    }
+	    return false;
+	}
 }

+ 3 - 1
wiki/官方API类库.md

@@ -20,6 +20,7 @@
 - 发货通知 (支付权限) 
 - 支付订单查询 (支付权限) 
 - 模板消息(支付权限) 
+- 语义理解(暂未开放) 
 
 
 ## 初始化动作 
@@ -39,7 +40,7 @@
 
 ## 新增Auth高级权限类方法:   
  *  checkAuth($appid,$appsecret,$token) 此处传入公众后台高级接口提供的appid和appsecret, 或者手动指定$token为access_token。函数将返回access_token操作令牌
- *  createMenu($data) 创建菜单 $data菜单结构详见 http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3 
+ *  createMenu($data) 创建菜单 $data菜单结构详见 **[自定义菜单创建接口](http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口)**
  *  getMenu() 获取菜单 
  *  deleteMenu() 删除菜单 
  *  uploadMedia($data, $type) 上传多媒体文件
@@ -78,6 +79,7 @@
  *  transfer_customer_service($customer_account) 转发多客服消息
  *  getCustomServiceKFlist() 获取多客服客服基本信息
  *  getCustomServiceOnlineKFlist() 获取多客服在线客服接待信息
+ *  querySemantic($uid,$query,$category,$latitude=0,$longitude=0,$city="",$region="") 语义理解接口 参数含义及返回的json内容请查看 **[微信语义理解接口](http://mp.weixin.qq.com/wiki/index.php?title=语义理解)**