1、增加卡券的api_ticket,区分jsapi_ticket,二者的获取逻辑不同;

2、增加小程序审核事件及审核事件推送消息SuccTime和Reason两个字段;
3、增加开放平台获取会员卡开卡插件参数接口。
4、增加开放平台手机端预授权接口实现;
This commit is contained in:
袁启勋
2018-09-27 08:34:07 +08:00
parent 9fcb4331c2
commit 34eb2f6aac
15 changed files with 353 additions and 27 deletions

View File

@ -24,6 +24,11 @@ public interface WxMpMemberCardService {
*/
String MEMBER_CARD_ACTIVATEUSERFORM = "https://api.weixin.qq.com/card/membercard/activateuserform/set";
/**
* 获取会员卡开卡插件参数
*/
String MEMBER_CARD_ACTIVATE_URL = "https://api.weixin.qq.com/card/membercard/activate/geturl";
/**
* 得到WxMpService
*/
@ -88,4 +93,13 @@ public interface WxMpMemberCardService {
*/
MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException;
/**
* 获取会员卡开卡插件参数(跳转型开卡组件需要参数)
*
* @param cardId
* @param outStr
* @return
* @throws WxErrorException
*/
ActivatePluginParam getActivatePluginParam(String cardId, String outStr) throws WxErrorException;
}

View File

@ -19,6 +19,11 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
/**
* 会员卡相关接口的实现类
*
@ -237,7 +242,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {
jsonObject.addProperty("code", code);
String responseContent = this.getWxMpService().post(MEMBER_CARD_USER_INFO_GET, jsonObject.toString());
log.debug("{}",responseContent);
log.debug("{}", responseContent);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement,
new TypeToken<WxMpMemberCardUserInfoResult>() {
@ -280,4 +285,91 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {
return MemberCardActivateUserFormResult.fromJson(responseContent);
}
/**
* 获取会员卡开卡插件参数(跳转型开卡组件需要参数)
*
* @param outStr
* @return
* @throws WxErrorException
*/
public ActivatePluginParam getActivatePluginParam(String cardId, String outStr) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("card_id", cardId);
params.addProperty("outer_str", outStr);
String response = this.wxMpService.post(MEMBER_CARD_ACTIVATE_URL, GSON.toJson(params));
ActivatePluginParamResult result = GSON.fromJson(response, ActivatePluginParamResult.class);
if (0 == result.getErrcode()) {
String url = result.getUrl();
try {
String decodedUrl = URLDecoder.decode(url, "UTF-8");
Map<String, String> resultMap = parseRequestUrl(decodedUrl);
ActivatePluginParam activatePluginParam = new ActivatePluginParam();
activatePluginParam.setEncryptCardId(resultMap.get("encrypt_card_id"));
activatePluginParam.setOuterStr(resultMap.get("outer_str"));
activatePluginParam.setBiz(resultMap.get("biz")+"==");
return activatePluginParam;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
/**
* 去掉url中的路径留下请求参数部分
*
* @param strURL url地址
* @return url请求参数部分
*/
private static String truncateUrlPage(String strURL) {
String strAllParam = null;
String[] arrSplit = null;
arrSplit = strURL.split("[?]");
if (strURL.length() > 1) {
if (arrSplit.length > 1) {
if (arrSplit[1] != null) {
strAllParam = arrSplit[1];
}
}
}
return strAllParam;
}
/**
* 解析出url参数中的键值对
* 如 "index.jsp?Action=del&id=123"解析出Action:del,id:123存入map中
*
* @param URL url地址
* @return url请求参数部分
*/
public static Map<String, String> parseRequestUrl(String URL) {
Map<String, String> mapRequest = new HashMap<String, String>();
String[] arrSplit = null;
String strUrlParam = truncateUrlPage(URL);
if (strUrlParam == null) {
return mapRequest;
}
arrSplit = strUrlParam.split("[&]");
for (String strSplit : arrSplit) {
String[] arrSplitEqual = null;
arrSplitEqual = strSplit.split("[=]");
//解析出键值
if (arrSplitEqual.length > 1) {
//正确解析
mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);
} else {
if (arrSplitEqual[0] != "") {
//只有参数没有值,不加入
mapRequest.put(arrSplitEqual[0], "");
}
}
}
return mapRequest;
}
}

View File

@ -0,0 +1,22 @@
package me.chanjar.weixin.mp.bean.membercard;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
/**
* @author yqx
* @date 2018/9/19
*/
@Data
public class ActivatePluginParam {
@SerializedName("encrypt_card_id")
String encryptCardId;
@SerializedName("outer_str")
String outerStr;
@SerializedName("biz")
String biz;
}

View File

@ -0,0 +1,18 @@
package me.chanjar.weixin.mp.bean.membercard;
import lombok.Data;
/**
* @author yqx
* @date 2018/9/19
*/
@Data
public class ActivatePluginParamResult {
private int errcode;
private String errmsg;
private String url;
}

View File

@ -541,6 +541,21 @@ public class WxMpXmlMessage implements Serializable {
@XStreamAlias("DeviceStatus")
private Integer deviceStatus;
///////////////////////////////////////
// 小程序 审核事件
///////////////////////////////////////
/**
* 审核成功时的时间(整形),时间戳
*/
@XStreamAlias("SuccTime")
private Long succTime;
/**
* 审核失败的原因
*/
@XStreamAlias("Reason")
private String reason;
public static WxMpXmlMessage fromXml(String xml) {
//修改微信变态的消息内容格式,方便解析
xml = xml.replace("</PicList><PicList>", "");

View File

@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.mp.api.WxMpCardService;
import me.chanjar.weixin.mp.api.WxMpMemberCardService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.bean.card.*;
@ -22,12 +23,12 @@ public class WxMpMemberCardServiceImplTest {
@Inject
protected WxMpService wxService;
private String cardId = "p2iQk1g2d03JXhVRDY5fZRVr236A";
private String cardId = "p2iQk1uwOUYlzHm4s-UYdZnABW88";
private String code = "435223630779";
private String openId = "o2iQk1u5X-XIJkatmAK1Q8VVuS90";
@Test
public void createMemberCard()throws Exception{
public void createMemberCard() throws Exception {
// String json = "{\"card\":{\"card_type\":\"MEMBER_CARD\",\"member_card\":{\"advanced_info\":{\"business_service\":\"BIZ_SERVICE_FREE_PARK,BIZ_SERVICE_WITH_PET,BIZ_SERVICE_FREE_WIFI\",\"text_image_list\":[{\"image_url\":\"http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGkENppDhyqhR8bz5BiaJkPT7e6bPVcfBx5cAOLro2N3U989n8WJltkjQ/0\",\"text\":\"8月8日随机免单\"}]},\"auto_activate\":false,\"background_pic_url\":\"http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0\",\"base_info\":{\"bind_openid\":false,\"brand_name\":\"商户名称\",\"can_give_friend\":false,\"can_share\":false,\"center_sub_title\":\"点击进入\",\"center_title\":\"商城首页\",\"center_url\":\"http://www.baidu.com\",\"code_type\":\"CODE_TYPE_QRCODE\",\"color\":\"Color090\",\"date_info\":{\"type\":\"DATE_TYPE_PERMANENT\"},\"description\":\"使用须知\",\"need_push_on_view\":false,\"notice\":\"测试会员卡\",\"service_phone\":\"4008803016\",\"title\":\"终生铂金卡\",\"use_all_locations\":true,\"use_custom_code\":false},\"prerogative\":\"享有特权说明\",\"supply_balance\":true,\"supply_bonus\":true,\"wx_activate\":false}}}";
// WxMpMemberCardCreateMessage createMessage = WxMpMemberCardCreateMessage.fromJson(json);
@ -105,10 +106,11 @@ public class WxMpMemberCardServiceImplTest {
/**
* 测试添加测试openid白名单
*
* @throws Exception
*/
@Test
public void testAddTestWhiteList()throws Exception {
public void testAddTestWhiteList() throws Exception {
WxMpCardService cardService = this.wxService.getCardService();
String response = cardService.addTestWhiteList(openId);
System.out.println(response);
@ -116,28 +118,38 @@ public class WxMpMemberCardServiceImplTest {
/**
* 测试创建会员卡投放二维码
*
* @throws Exception
*/
@Test
public void testCreateQrcodeMemberCard()throws Exception{
public void testCreateQrcodeMemberCard() throws Exception {
WxMpCardService cardService = this.wxService.getCardService();
WxMpCardQrcodeCreateResult response = cardService.createQrcodeCard(cardId,"test");
WxMpCardQrcodeCreateResult response = cardService.createQrcodeCard(cardId, "test");
System.out.println(response);
}
/**
* 测试创建货架接口
*
* @throws Exception
*/
@Test
public void testCreateLandingPage()throws Exception{
public void testCreateLandingPage() throws Exception {
WxMpCardService cardService = this.wxService.getCardService();
WxMpCardLandingPageCreateRequest request = new WxMpCardLandingPageCreateRequest();
request.setBanner("http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0");
request.setTitle("会员卡1");
request.setScene(CardSceneType.SCENE_H5.name());
request.addCard(cardId,"http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0");
request.addCard(cardId, "http://mmbiz.qpic.cn/mmbiz_jpg/upuF1LhUF8LjCLCFcQicgEiazFeonwDllGl6ibk4v5iaJDAbs7dGJU7iclOJ6nh7Hnz6ZsfDL8tGEeQVJyuhKsMFxUQ/0");
WxMpCardLandingPageCreateResult response = cardService.createLandingPage(request);
System.out.println(response);
}
@Test
public void testGetActivateUrl() throws Exception {
WxMpMemberCardService memberCardService = this.wxService.getMemberCardService();
ActivatePluginParam response = memberCardService.getActivatePluginParam(cardId, "test");
System.out.println(response);
}
}