|
@@ -3,6 +3,7 @@ package com.yunzhi.marketing.common;
|
3
|
3
|
import com.alibaba.fastjson.JSONObject;
|
4
|
4
|
import com.yunzhi.marketing.config.WorkConfig;
|
5
|
5
|
import lombok.extern.slf4j.Slf4j;
|
|
6
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
6
|
7
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
7
|
8
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
8
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,19 +34,24 @@ public class WorkWxUtils {
|
33
|
34
|
throw new Exception("房间号或者人员openid不能为空");
|
34
|
35
|
}
|
35
|
36
|
|
36
|
|
- String url = "/cgi-bin/living/get_living_code";
|
37
|
|
- JSONObject params = new JSONObject();
|
38
|
|
- params.put("livingid", livingid);
|
39
|
|
- params.put("openid", openid);
|
|
37
|
+ try {
|
|
38
|
+ String url = wxCpService.getWxCpConfigStorage().getApiUrl("/cgi-bin/living/get_living_code");
|
|
39
|
+ JSONObject params = new JSONObject();
|
|
40
|
+ params.put("livingid", livingid);
|
|
41
|
+ params.put("openid", openid);
|
40
|
42
|
|
41
|
|
- String response = wxCpService.post(url, params.toJSONString());
|
42
|
|
- JSONObject result = JSONObject.parseObject(response);
|
43
|
|
-
|
44
|
|
- String errmsg = result.getString("errmsg");
|
45
|
|
- if ("ok".equals(errmsg)) {
|
|
43
|
+ String response = wxCpService.post(url, params.toJSONString());
|
|
44
|
+ JSONObject result = JSONObject.parseObject(response);
|
46
|
45
|
return result.getString("living_code");
|
47
|
|
- } else {
|
48
|
|
- throw new Exception(String.format("获取直播凭证失败: %s", errmsg));
|
|
46
|
+ } catch (WxErrorException e) {
|
|
47
|
+ if (90601 == e.getError().getErrorCode()) {
|
|
48
|
+ throw new Exception("直播房间不存在");
|
|
49
|
+ } else {
|
|
50
|
+ throw new Exception(String.format("获取直播凭证失败: %s", e.getError().getErrorMsg()));
|
|
51
|
+ }
|
|
52
|
+ } catch (Exception e) {
|
|
53
|
+ e.printStackTrace();
|
|
54
|
+ throw e;
|
49
|
55
|
}
|
50
|
56
|
}
|
51
|
57
|
}
|