瀏覽代碼

抽取卡券相关接口请求URL到其接口类中 #195

master
Binary Wang 8 年之前
父節點
當前提交
a436e62103
共有 2 個檔案被更改,包括 12 行新增12 行删除
  1. +6
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java
  2. +6
    -12
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java

+ 6
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java 查看文件

@@ -10,6 +10,12 @@ import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
* @author YuJian(mgcnrx11@hotmail.com) on 01/11/2016
*/
public interface WxMpCardService {
String CARD_GET = "https://api.weixin.qq.com/card/get";
String CARD_GET_TICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card";
String CARD_CODE_DECRYPT = "https://api.weixin.qq.com/card/code/decrypt";
String CARD_CODE_GET = "https://api.weixin.qq.com/card/code/get";
String CARD_CODE_CONSUME = "https://api.weixin.qq.com/card/code/consume";
String CARD_CODE_MARK = "https://api.weixin.qq.com/card/code/mark";

/**
* 得到WxMpService


+ 6
- 12
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java 查看文件

@@ -74,8 +74,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
}

if (this.getWxMpService().getWxMpConfigStorage().isCardApiTicketExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card";
String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor.create(this.getWxMpService().getRequestHttp()), url, null);
String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor.create(this.getWxMpService().getRequestHttp()), CARD_GET_TICKET, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String cardApiTicket = tmpJsonObject.get("ticket").getAsString();
@@ -129,10 +128,9 @@ public class WxMpCardServiceImpl implements WxMpCardService {
*/
@Override
public String decryptCardCode(String encryptCode) throws WxErrorException {
String url = "https://api.weixin.qq.com/card/code/decrypt";
JsonObject param = new JsonObject();
param.addProperty("encrypt_code", encryptCode);
String responseContent = this.wxMpService.post(url, param.toString());
String responseContent = this.wxMpService.post(CARD_CODE_DECRYPT, param.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code");
@@ -149,12 +147,11 @@ public class WxMpCardServiceImpl implements WxMpCardService {
*/
@Override
public WxMpCardResult queryCardCode(String cardId, String code, boolean checkConsume) throws WxErrorException {
String url = "https://api.weixin.qq.com/card/code/get";
JsonObject param = new JsonObject();
param.addProperty("card_id", cardId);
param.addProperty("code", code);
param.addProperty("check_consume", checkConsume);
String responseContent = this.wxMpService.post(url, param.toString());
String responseContent = this.wxMpService.post(CARD_CODE_GET, param.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement,
new TypeToken<WxMpCardResult>() {
@@ -183,7 +180,6 @@ public class WxMpCardServiceImpl implements WxMpCardService {
*/
@Override
public String consumeCardCode(String code, String cardId) throws WxErrorException {
String url = "https://api.weixin.qq.com/card/code/consume";
JsonObject param = new JsonObject();
param.addProperty("code", code);

@@ -191,7 +187,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
param.addProperty("card_id", cardId);
}

return this.wxMpService.post(url, param.toString());
return this.wxMpService.post(CARD_CODE_CONSUME, param.toString());
}

/**
@@ -207,13 +203,12 @@ public class WxMpCardServiceImpl implements WxMpCardService {
@Override
public void markCardCode(String code, String cardId, String openId, boolean isMark) throws
WxErrorException {
String url = "https://api.weixin.qq.com/card/code/mark";
JsonObject param = new JsonObject();
param.addProperty("code", code);
param.addProperty("card_id", cardId);
param.addProperty("openid", openId);
param.addProperty("is_mark", isMark);
String responseContent = this.getWxMpService().post(url, param.toString());
String responseContent = this.getWxMpService().post(CARD_CODE_MARK, param.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
WxMpCardResult cardResult = WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement,
new TypeToken<WxMpCardResult>() {
@@ -225,10 +220,9 @@ public class WxMpCardServiceImpl implements WxMpCardService {

@Override
public String getCardDetail(String cardId) throws WxErrorException {
String url = "https://api.weixin.qq.com/card/get";
JsonObject param = new JsonObject();
param.addProperty("card_id", cardId);
String responseContent = this.wxMpService.post(url, param.toString());
String responseContent = this.wxMpService.post(CARD_GET, param.toString());

// 判断返回值
JsonObject json = (new JsonParser()).parse(responseContent).getAsJsonObject();


Loading…
取消
儲存