Skip to content

Commit

Permalink
Merge pull request #2 from Wechat-Group/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
f00lish authored Sep 12, 2020
2 parents 123dbb6 + b15142a commit 991f39e
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private RedissonClient getRedissonClient() {
Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
.setDatabase(redis.getDatabase())
.setPassword(redis.getPassword());
config.setTransportMode(TransportMode.NIO);
return Redisson.create(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.chanjar.weixin.cp.constant;


import lombok.experimental.UtilityClass;

/**
* <pre>
* 企业微信api地址常量类
Expand All @@ -9,6 +11,7 @@
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@UtilityClass
public final class WxCpApiPathConsts {
public static final String DEFAULT_CP_BASE_URL = "https://qyapi.weixin.qq.com";

Expand All @@ -26,6 +29,7 @@ public final class WxCpApiPathConsts {
* 消息推送相关接口
* https://work.weixin.qq.com/api/doc/90000/90135/90235
*/
@UtilityClass
public static class Message {
/**
* 发送应用消息
Expand All @@ -38,45 +42,52 @@ public static class Message {
public static final String LINKEDCORP_MESSAGE_SEND = "/cgi-bin/linkedcorp/message/send";
}

@UtilityClass
public static class Agent {
public static final String AGENT_GET = "/cgi-bin/agent/get?agentid=%d";
public static final String AGENT_SET = "/cgi-bin/agent/set";
public static final String AGENT_LIST = "/cgi-bin/agent/list";
}

@UtilityClass
public static class OAuth2 {
public static final String GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
public static final String GET_USER_DETAIL = "/cgi-bin/user/getuserdetail";
public static final String URL_OAUTH2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
}

@UtilityClass
public static class Chat {
public static final String APPCHAT_CREATE = "/cgi-bin/appchat/create";
public static final String APPCHAT_UPDATE = "/cgi-bin/appchat/update";
public static final String APPCHAT_GET_CHATID = "/cgi-bin/appchat/get?chatid=";
public static final String APPCHAT_SEND = "/cgi-bin/appchat/send";
}

@UtilityClass
public static class Department {
public static final String DEPARTMENT_CREATE = "/cgi-bin/department/create";
public static final String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
public static final String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
public static final String DEPARTMENT_LIST = "/cgi-bin/department/list";
}

@UtilityClass
public static class Media {
public static final String MEDIA_GET = "/cgi-bin/media/get";
public static final String MEDIA_UPLOAD = "/cgi-bin/media/upload?type=";
public static final String IMG_UPLOAD = "/cgi-bin/media/uploadimg";
public static final String JSSDK_MEDIA_GET = "/cgi-bin/media/get/jssdk";
}

@UtilityClass
public static class Menu {
public static final String MENU_CREATE = "/cgi-bin/menu/create?agentid=%d";
public static final String MENU_DELETE = "/cgi-bin/menu/delete?agentid=%d";
public static final String MENU_GET = "/cgi-bin/menu/get?agentid=%d";
}

@UtilityClass
public static class Oa {
public static final String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata";
public static final String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption";
Expand All @@ -87,6 +98,7 @@ public static class Oa {
public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent";
}

@UtilityClass
public static class Tag {
public static final String TAG_CREATE = "/cgi-bin/tag/create";
public static final String TAG_UPDATE = "/cgi-bin/tag/update";
Expand All @@ -97,10 +109,12 @@ public static class Tag {
public static final String TAG_DEL_TAG_USERS = "/cgi-bin/tag/deltagusers";
}

@UtilityClass
public static class TaskCard {
public static final String UPDATE_TASK_CARD = "/cgi-bin/message/update_taskcard";
}

@UtilityClass
public static class Tp {
public static final String JSCODE_TO_SESSION = "/cgi-bin/service/miniprogram/jscode2session";
public static final String GET_CORP_TOKEN = "/cgi-bin/service/get_corp_token";
Expand All @@ -111,6 +125,7 @@ public static class Tp {
public static final String GET_AUTH_INFO = "/cgi-bin/service/get_auth_info";
}

@UtilityClass
public static class User {
public static final String USER_AUTHENTICATE = "/cgi-bin/user/authsucc?userid=";
public static final String USER_CREATE = "/cgi-bin/user/create";
Expand All @@ -127,6 +142,7 @@ public static class User {
public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
}

@UtilityClass
public static class ExternalContact {
@Deprecated
public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.chanjar.weixin.cp.constant;

import lombok.experimental.UtilityClass;

/**
* <pre>
* 企业微信常量
Expand All @@ -8,11 +10,13 @@
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@UtilityClass
public class WxCpConsts {
/**
* 企业微信端推送过来的事件类型.
* 参考文档:https://work.weixin.qq.com/api/doc#12974
*/
@UtilityClass
public static class EventType {
/**
* 成员关注事件.
Expand Down Expand Up @@ -105,6 +109,7 @@ public static class EventType {
/**
* 企业外部联系人变更事件的CHANGE_TYPE
*/
@UtilityClass
public static class ExternalContactChangeType {
/**
* 新增外部联系人
Expand All @@ -128,6 +133,7 @@ public static class ExternalContactChangeType {
/**
* 企业微信通讯录变更事件.
*/
@UtilityClass
public static class ContactChangeType {
/**
* 新增成员事件.
Expand Down Expand Up @@ -169,6 +175,7 @@ public static class ContactChangeType {
/**
* 互联企业发送应用消息的消息类型.
*/
@UtilityClass
public static class LinkedCorpMsgType {
/**
* 文本消息.
Expand Down Expand Up @@ -213,6 +220,7 @@ public static class LinkedCorpMsgType {
/**
* 群机器人的消息类型.
*/
@UtilityClass
public static class GroupRobotMsgType {
/**
* 文本消息.
Expand All @@ -238,6 +246,7 @@ public static class GroupRobotMsgType {
/**
* 应用推送消息的消息类型.
*/
@UtilityClass
public static class AppChatMsgType {
/**
* 文本消息.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import me.chanjar.weixin.common.error.WxErrorException;

import java.util.List;
Expand Down Expand Up @@ -37,7 +37,7 @@ public interface WxMaLiveGoodsService {
* @return 返回auditId、goodsId
* @throws WxErrorException .
*/
WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException;

/**
* 撤回审核
Expand Down Expand Up @@ -91,7 +91,7 @@ public interface WxMaLiveGoodsService {
* @return 更新商品是否成功
* @throws WxErrorException .
*/
boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException;

/**
* 获取商品状态
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
import me.chanjar.weixin.common.error.WxErrorException;

import java.util.List;
Expand Down Expand Up @@ -31,7 +31,7 @@ public interface WxMaLiveService {
* @return .
* @throws WxErrorException .
*/
Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException;
Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;

/**
* 获取直播房间列表.(分页)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import cn.binarywang.wx.miniapp.api.WxMaLiveGoodsService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;

Expand All @@ -32,27 +30,17 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
private final WxMaService wxMaService;

@Override
public WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("goodsInfo", goods);
String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaLiveResult.fromJson(jsonObject.toString());
public WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
return WxMaLiveResult.fromJson(this.wxMaService.post(ADD_GOODS,
WxMaGsonBuilder.create().toJson(ImmutableMap.of("goodsInfo", goods))));
}

@Override
public boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException {
Map<String, Integer> map = new HashMap<>(4);
map.put("auditId", auditId);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
return true;
}

Expand All @@ -62,33 +50,22 @@ public String auditGoods(Integer goodsId) throws WxErrorException {
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("auditId").getAsString();
}

@Override
public boolean deleteGoods(Integer goodsId) throws WxErrorException {
Map<String, Integer> map = new HashMap<>(2);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
return true;
}

@Override
public boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
public boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("goodsInfo", goods);
String responseContent = this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
return true;
}

Expand All @@ -97,21 +74,14 @@ public WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorEx
Map<String, Object> map = new HashMap<>(2);
map.put("goods_ids", goodsIds);
String responseContent = this.wxMaService.post(GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaLiveResult.fromJson(jsonObject.toString());
return WxMaLiveResult.fromJson(responseContent);
}

@Override
public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException {
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("status", status, "offset", offset, "limit", limit);
String responseContent = wxMaService.get(GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
JsonArray goodsArr = jsonObject.getAsJsonArray("goods");
if (goodsArr.size() > 0) {
for (int i = 0; i < goodsArr.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import cn.binarywang.wx.miniapp.api.WxMaLiveService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
private final WxMaService wxMaService;

@Override
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
public Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
Expand Down
Loading

0 comments on commit 991f39e

Please sign in to comment.