|
@@ -690,10 +690,11 @@ public class WeixinServiceImpl implements WeixinService {
|
|
* 开通微信卡券
|
|
* 开通微信卡券
|
|
*
|
|
*
|
|
* @param merchantId 商户ID
|
|
* @param merchantId 商户ID
|
|
|
|
+ * @param wxCardId 微信会员卡ID
|
|
* @return
|
|
* @return
|
|
* */
|
|
* */
|
|
@Override
|
|
@Override
|
|
- public String createWxCard(Integer merchantId) throws BusinessCheckException {
|
|
|
|
|
|
+ public String createWxCard(Integer merchantId, String wxCardId) throws BusinessCheckException {
|
|
String cardId = "";
|
|
String cardId = "";
|
|
try {
|
|
try {
|
|
MtSetting mtSetting = settingService.querySettingByName(merchantId, UserSettingEnum.WX_MEMBER_CARD.getKey());
|
|
MtSetting mtSetting = settingService.querySettingByName(merchantId, UserSettingEnum.WX_MEMBER_CARD.getKey());
|
|
@@ -703,63 +704,107 @@ public class WeixinServiceImpl implements WeixinService {
|
|
WxCardDto wxCardDto = JsonUtil.parseObject(mtSetting.getValue(), WxCardDto.class);
|
|
WxCardDto wxCardDto = JsonUtil.parseObject(mtSetting.getValue(), WxCardDto.class);
|
|
|
|
|
|
String accessToken = getAccessToken(merchantId, false,true);
|
|
String accessToken = getAccessToken(merchantId, false,true);
|
|
- String url = "https://api.weixin.qq.com/card/create?access_token=" + accessToken;
|
|
|
|
|
|
+ String createUrl = "https://api.weixin.qq.com/card/create?access_token=" + accessToken;
|
|
|
|
+ String updateUrl = "https://api.weixin.qq.com/card/update?access_token=" + accessToken;
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> card = new HashMap<>();
|
|
Map<String, Object> card = new HashMap<>();
|
|
- card.put("card_type", "MEMBER_CARD");
|
|
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ card.put("card_type", "MEMBER_CARD");
|
|
|
|
+ }
|
|
Map<String, Object> memberCard = new HashMap<>();
|
|
Map<String, Object> memberCard = new HashMap<>();
|
|
- memberCard.put("background_pic_url", wxCardDto.getBackgroundUrl());
|
|
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getBackgroundUrl())) {
|
|
|
|
+ memberCard.put("background_pic_url", wxCardDto.getBackgroundUrl());
|
|
|
|
+ }
|
|
|
|
|
|
// baseInfo
|
|
// baseInfo
|
|
Map<String, Object> baseInfo = new HashMap<>();
|
|
Map<String, Object> baseInfo = new HashMap<>();
|
|
- baseInfo.put("logo_url", wxCardDto.getLogoUrl());
|
|
|
|
- baseInfo.put("brand_name", wxCardDto.getBrandName());
|
|
|
|
|
|
+ baseInfo.put("logo_url", "https://fuint-cn.oss-cn-shenzhen.aliyuncs.com/images/logo.png");
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ baseInfo.put("brand_name", wxCardDto.getBrandName());
|
|
|
|
+ }
|
|
baseInfo.put("code_type", "CODE_TYPE_TEXT");
|
|
baseInfo.put("code_type", "CODE_TYPE_TEXT");
|
|
baseInfo.put("title", wxCardDto.getTitle());
|
|
baseInfo.put("title", wxCardDto.getTitle());
|
|
baseInfo.put("color", wxCardDto.getColor());
|
|
baseInfo.put("color", wxCardDto.getColor());
|
|
baseInfo.put("notice", wxCardDto.getNotice());
|
|
baseInfo.put("notice", wxCardDto.getNotice());
|
|
- baseInfo.put("service_phone", wxCardDto.getServicePhone());
|
|
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getServicePhone())) {
|
|
|
|
+ baseInfo.put("service_phone", wxCardDto.getServicePhone());
|
|
|
|
+ }
|
|
baseInfo.put("description", wxCardDto.getDescription());
|
|
baseInfo.put("description", wxCardDto.getDescription());
|
|
Map<String, Object> dateInfo = new HashMap<>();
|
|
Map<String, Object> dateInfo = new HashMap<>();
|
|
dateInfo.put("type", "DATE_TYPE_PERMANENT");
|
|
dateInfo.put("type", "DATE_TYPE_PERMANENT");
|
|
- baseInfo.put("date_info", dateInfo);
|
|
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ baseInfo.put("date_info", dateInfo);
|
|
|
|
+ }
|
|
Map<String, Object> sku = new HashMap<>();
|
|
Map<String, Object> sku = new HashMap<>();
|
|
sku.put("quantity", Constants.ALL_ROWS);
|
|
sku.put("quantity", Constants.ALL_ROWS);
|
|
- baseInfo.put("sku", sku);
|
|
|
|
- baseInfo.put("get_limit", 1);
|
|
|
|
- baseInfo.put("use_custom_code", false);
|
|
|
|
- baseInfo.put("bind_openid", false);
|
|
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ baseInfo.put("sku", sku);
|
|
|
|
+ baseInfo.put("get_limit", 1);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ baseInfo.put("use_custom_code", false);
|
|
|
|
+ baseInfo.put("bind_openid", false);
|
|
|
|
+ }
|
|
baseInfo.put("can_give_friend", false);
|
|
baseInfo.put("can_give_friend", false);
|
|
- baseInfo.put("location_id_list", null);
|
|
|
|
- baseInfo.put("custom_url_name", wxCardDto.getCustomUrlName());
|
|
|
|
- baseInfo.put("custom_url", wxCardDto.getCustomUrl());
|
|
|
|
- baseInfo.put("custom_url_sub_title", wxCardDto.getCustomUrlSubTitle());
|
|
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ baseInfo.put("location_id_list", null);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getCustomUrlName())) {
|
|
|
|
+ baseInfo.put("custom_url_name", wxCardDto.getCustomUrlName());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getCustomUrl())) {
|
|
|
|
+ baseInfo.put("custom_url", wxCardDto.getCustomUrl());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getCustomUrlSubTitle())) {
|
|
|
|
+ baseInfo.put("custom_url_sub_title", wxCardDto.getCustomUrlSubTitle());
|
|
|
|
+ }
|
|
baseInfo.put("need_push_on_view", true);
|
|
baseInfo.put("need_push_on_view", true);
|
|
memberCard.put("base_info", baseInfo);
|
|
memberCard.put("base_info", baseInfo);
|
|
|
|
|
|
// 特权说明
|
|
// 特权说明
|
|
- memberCard.put("prerogative", wxCardDto.getPrerogative());
|
|
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getPrerogative())) {
|
|
|
|
+ memberCard.put("prerogative", wxCardDto.getPrerogative());
|
|
|
|
+ }
|
|
// 自动激活
|
|
// 自动激活
|
|
memberCard.put("auto_activate", true);
|
|
memberCard.put("auto_activate", true);
|
|
memberCard.put("supply_bonus", wxCardDto.getSupplyBonus());
|
|
memberCard.put("supply_bonus", wxCardDto.getSupplyBonus());
|
|
- memberCard.put("bonus_url", wxCardDto.getBonusUrl());
|
|
|
|
- memberCard.put("supply_balance", wxCardDto.getSupplyBalance());
|
|
|
|
- memberCard.put("balance_url", wxCardDto.getBalanceUrl());
|
|
|
|
-
|
|
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getBonusUrl())) {
|
|
|
|
+ memberCard.put("bonus_url", wxCardDto.getBonusUrl());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ memberCard.put("supply_balance", wxCardDto.getSupplyBalance());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardDto.getBalanceUrl())) {
|
|
|
|
+ memberCard.put("balance_url", wxCardDto.getBalanceUrl());
|
|
|
|
+ }
|
|
card.put("member_card", memberCard);
|
|
card.put("member_card", memberCard);
|
|
- params.put("card", card);
|
|
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ params.put("card", card);
|
|
|
|
+ } else {
|
|
|
|
+ card.put("card_id", wxCardId);
|
|
|
|
+ params = card;
|
|
|
|
+ }
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
String reqDataJson = mapper.writeValueAsString(params);
|
|
String reqDataJson = mapper.writeValueAsString(params);
|
|
-
|
|
|
|
|
|
+ String url = createUrl;
|
|
|
|
+ if (StringUtil.isNotEmpty(wxCardId)) {
|
|
|
|
+ url = updateUrl;
|
|
|
|
+ }
|
|
|
|
+ logger.info("开通微信卡券接口url:{},请求参数:{}", url, reqDataJson);
|
|
String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJson);
|
|
String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJson);
|
|
- logger.error("开通微信卡券接口返回:{}", response);
|
|
|
|
|
|
+ logger.info("开通微信卡券接口返回:{}", response);
|
|
JSONObject data = (JSONObject) JSONObject.parse(response);
|
|
JSONObject data = (JSONObject) JSONObject.parse(response);
|
|
if (data.get("errcode").toString().equals("0")) {
|
|
if (data.get("errcode").toString().equals("0")) {
|
|
- cardId = data.get("card_id").toString();
|
|
|
|
|
|
+ if (StringUtil.isEmpty(wxCardId)) {
|
|
|
|
+ cardId = data.get("card_id").toString();
|
|
|
|
+ } else {
|
|
|
|
+ cardId = wxCardId;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- throw new BusinessCheckException("开通微信卡券出错啦:"+data.get("errmsg").toString());
|
|
|
|
|
|
+ logger.error("开通微信卡券出错啦{}", data.get("errmsg").toString());
|
|
|
|
+ throw new BusinessCheckException("开通微信卡券出错啦:" + data.get("errmsg").toString());
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
logger.error("开通微信卡券出错啦:{}", e.getMessage());
|
|
logger.error("开通微信卡券出错啦:{}", e.getMessage());
|