Skip to content

Develop #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest;
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult;
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;

/**
* 卡券相关接口
*
* @author YuJian(mgcnrx11@hotmail.com) on 01/11/2016
* @author yuanqixun 2018-08-29
*/
public interface WxMpCardService {
String CARD_GET = "https://api.weixin.qq.com/card/get";
Expand All @@ -16,6 +20,9 @@ public interface WxMpCardService {
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";
String CARD_TEST_WHITELIST = "https://api.weixin.qq.com/card/testwhitelist/set";
String CARD_QRCODE_CREAET = "https://api.weixin.qq.com/card/qrcode/create";
String CARD_LANDING_PAGE_CREAET = "https://api.weixin.qq.com/card/landingpage/create";

/**
* 得到WxMpService
Expand Down Expand Up @@ -122,4 +129,27 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
* <br> 可由 com.google.gson.JsonParser#parse 等方法直接取JSON串中的某个字段。
*/
String getCardDetail(String cardId) throws WxErrorException;

/**
* 添加测试白名单
* @param openid 用户的openid
* @return
*/
String addTestWhiteList(String openid) throws WxErrorException;

/**
* 创建卡券二维码
* @param cardId 卡券编号
* @param outerStr 二维码标识
* @return WxMpCardQrcodeCreateResult
*/
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException;

/**
* 创建卡券货架
* @param createRequest 货架创建参数
* @return
* @throws WxErrorException
*/
WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest createRequest) throws WxErrorException;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package me.chanjar.weixin.mp.api;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult;
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
import me.chanjar.weixin.mp.bean.membercard.*;

/**
* 会员卡相关接口
Expand All @@ -19,11 +18,27 @@ public interface WxMpMemberCardService {
*/
WxMpService getWxMpService();

/**
* 会员卡创建接口
* @param createJson
* @return
* @throws WxErrorException
*/
WxMpCardCreateResult createMemberCard(String createJson) throws WxErrorException;

/**
* 会员卡创建接口
* @param createMessageMessage
* @return WxMpCardCreateResult
* @throws WxErrorException
*/
WxMpCardCreateResult createMemberCard(WxMpMemberCardCreateMessage createMessageMessage) throws WxErrorException;

/**
* 会员卡激活接口
*
* @param activatedMessage 激活所需参数
* @return 调用返回的JSON字符串。
* @return 返回json字符串
* @throws WxErrorException 接口调用失败抛出的异常
*/
String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException;
Expand All @@ -50,4 +65,5 @@ public interface WxMpMemberCardService {
* @throws WxErrorException 接口调用失败抛出的异常
*/
WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) throws WxErrorException;

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.chanjar.weixin.mp.api.impl;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.common.error.WxError;
Expand All @@ -13,6 +10,9 @@
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.mp.api.WxMpCardService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest;
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult;
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.slf4j.Logger;
Expand All @@ -30,6 +30,8 @@ public class WxMpCardServiceImpl implements WxMpCardService {

private WxMpService wxMpService;

private static final Gson GSON = new Gson();

public WxMpCardServiceImpl(WxMpService wxMpService) {
this.wxMpService = wxMpService;
}
Expand Down Expand Up @@ -236,4 +238,51 @@ public String getCardDetail(String cardId) throws WxErrorException {

return responseContent;
}

/**
* 添加测试白名单
*
* @param openid 用户的openid
* @return
*/
public String addTestWhiteList(String openid) throws WxErrorException {
JsonArray array = new JsonArray();
array.add(openid);
JsonObject jsonObject = new JsonObject();
jsonObject.add("openid", array);
String respone = this.wxMpService.post(CARD_TEST_WHITELIST, GSON.toJson(jsonObject));
return respone;
}

/**
* 创建卡券二维码
* @param cardId
* @param outerStr
* @return
*/
public WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("action_name", "QR_CARD");
jsonObject.addProperty("expire_seconds", 1800);
JsonObject actionInfoJson = new JsonObject();
JsonObject cardJson = new JsonObject();
cardJson.addProperty("card_id", cardId);
cardJson.addProperty("outer_str", outerStr);
actionInfoJson.add("card", cardJson);
jsonObject.add("action_info", actionInfoJson);
String response = this.wxMpService.post(CARD_QRCODE_CREAET, GSON.toJson(jsonObject));
return WxMpCardQrcodeCreateResult.fromJson(response);
}

/**
* 创建卡券货架接口
* @param request
* @return
* @throws WxErrorException
*/
@Override
public WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest request) throws WxErrorException {
String response = this.wxMpService.post(CARD_LANDING_PAGE_CREAET,GSON.toJson(request));
return WxMpCardLandingPageCreateResult.fromJson(response);
}
}
Loading