Browse Source

fixed 微信会员卡功能

fushengqian 1 year ago
parent
commit
0985f3ca20

+ 8 - 4
fuint-application/src/main/java/com/fuint/common/http/HttpRESTDataClient.java

@@ -1,10 +1,12 @@
 package com.fuint.common.http;
 
+import com.fuint.utils.StringUtil;
+import okhttp3.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 import java.io.IOException;
-import okhttp3.*;
+
 
 /**
  * 调用REST接口并解析数据
@@ -43,11 +45,13 @@ public class HttpRESTDataClient {
     }
 
     public static String requestPost(String url, String contentType, String postData) throws IOException {
-        String postBody = postData;
-        MediaType mediaType = MediaType.parse(contentType);
+        MediaType mediaType = null;
+        if (StringUtil.isNotEmpty(contentType)) {
+            mediaType = MediaType.parse(contentType);
+        }
         Request request = new Request.Builder()
                 .url(url)
-                .post(RequestBody.create(mediaType, postBody))
+                .post(RequestBody.create(mediaType, postData))
                 .build();
         Response response = client.newCall(request).execute();
         if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

+ 1 - 2
fuint-application/src/main/java/com/fuint/common/service/WeixinService.java

@@ -147,9 +147,8 @@ public interface WeixinService {
      * 开通微信卡券
      *
      * @param merchantId 商户ID
-     * @param storeId 店铺ID
      * @return
      * */
-    String createWxCard(Integer merchantId, Integer storeId);
+    String createWxCard(Integer merchantId);
 
 }

+ 54 - 10
fuint-application/src/main/java/com/fuint/common/service/impl/WeixinServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONArray;
 import com.aliyun.oss.OSS;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fuint.common.bean.H5SceneInfo;
 import com.fuint.common.bean.WxPayBean;
 import com.fuint.common.dto.OrderDto;
@@ -38,7 +39,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.core.env.Environment;
 import weixin.popular.util.JsonUtil;
-
 import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
@@ -112,8 +112,8 @@ public class WeixinServiceImpl implements WeixinService {
      * */
     @Override
     public String getAccessToken(Integer merchantId, boolean useCache) throws BusinessCheckException {
-        String wxAppId = env.getProperty("wxpay.appId");
-        String wxAppSecret = env.getProperty("wxpay.appSecret");
+        String wxAppId = env.getProperty("weixin.official.appId");
+        String wxAppSecret = env.getProperty("weixin.official.appSecret");
         String tokenKey = FUINT_ACCESS_TOKEN_PRE;
         if (merchantId != null && merchantId > 0) {
             MtMerchant mtMerchant = merchantService.queryMerchantById(merchantId);
@@ -521,7 +521,7 @@ public class WeixinServiceImpl implements WeixinService {
             logger.info("WeixinService sendSubscribeMessage response={}", response);
             JSONObject json = (JSONObject) JSONObject.parse(response);
             if (json.get("errcode").toString().equals("40001")) {
-                getAccessToken(merchantId, false);
+                getAccessToken(merchantId, true);
                 logger.error("发送订阅消息出错error1:" + json.get("errcode").toString());
                 return false;
             } else if (!json.get("errcode").toString().equals("0")) {
@@ -681,20 +681,64 @@ public class WeixinServiceImpl implements WeixinService {
      * 开通微信卡券
      *
      * @param merchantId 商户ID
-     * @param storeId 店铺ID
      * @return
      * */
     @Override
-    public String createWxCard(Integer merchantId, Integer storeId) {
+    public String createWxCard(Integer merchantId) {
         String cardId = "";
         try {
             String accessToken = getAccessToken(merchantId, true);
-            String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken;
-            String reqDataJson = "";
+            String url = "https://api.weixin.qq.com/card/create?access_token=" + accessToken;
 
             Map<String, Object> params = new HashMap<>();
-            params.put("access_token", accessToken);
-            reqDataJson = JsonUtil.toJSONString(params);
+            Map<String, Object> card = new HashMap<>();
+            card.put("card_type", "MEMBER_CARD");
+            Map<String, Object> memberCard = new HashMap<>();
+            memberCard.put("background_pic_url", null);
+
+            // baseInfo
+            Map<String, Object> baseInfo = new HashMap<>();
+            baseInfo.put("logo_url", "");
+            baseInfo.put("brand_name", "小隅安");
+            baseInfo.put("code_type", "CODE_TYPE_TEXT");
+            baseInfo.put("title", "小隅安会员卡");
+            baseInfo.put("color", "Color010");
+            baseInfo.put("notice", "使用时向服务员出示此券");
+            baseInfo.put("service_phone", "0898-88888888");
+            baseInfo.put("description", "不可与其他优惠同享");
+            Map<String, Object> dateInfo = new HashMap<>();
+            dateInfo.put("type", "DATE_TYPE_PERMANENT");
+            baseInfo.put("date_info", dateInfo);
+            Map<String, Object> sku = new HashMap<>();
+            sku.put("quantity", 50000000);
+            baseInfo.put("sku", sku);
+            baseInfo.put("get_limit", 3);
+            baseInfo.put("use_custom_code", false);
+            baseInfo.put("bind_openid", false);
+            baseInfo.put("can_give_friend", false);
+            baseInfo.put("location_id_list", null);
+            baseInfo.put("custom_url_name", "立即使用");
+            baseInfo.put("custom_url", "https://www.fuint.cn/h5/");
+            baseInfo.put("custom_url_sub_title", "6个汉字tips");
+            baseInfo.put("promotion_url_name", "营销入口");
+            baseInfo.put("promotion_url", "https://www.fuint.cn/h5/");
+            baseInfo.put("need_push_on_view", true);
+            memberCard.put("base_info", baseInfo);
+
+            // 特权说明
+            memberCard.put("prerogative", "会员卡特权说明,限制1024汉字。");
+            // 自动激活
+            memberCard.put("auto_activate", true);
+            memberCard.put("supply_bonus", true);
+            memberCard.put("bonus_url", "https://www.fuint.cn/h5/");
+            memberCard.put("supply_balance", false);
+            memberCard.put("balance_url", "https://www.fuint.cn/h5/");
+
+            card.put("member_card", memberCard);
+            params.put("card", card);
+
+            ObjectMapper mapper = new ObjectMapper();
+            String reqDataJson = mapper.writeValueAsString(params);
 
             String response = HttpRESTDataClient.requestPost(url, "application/json; charset=utf-8", reqDataJson);
             logger.error("开通微信卡券接口返回:{}", response);

+ 2 - 1
fuint-utils/src/main/java/com/fuint/utils/HttpUtil.java

@@ -1,7 +1,6 @@
 package com.fuint.utils;
 
 import org.apache.commons.lang.StringUtils;
-
 import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -10,6 +9,8 @@ import java.util.Iterator;
 import java.util.Map;
 
 /**
+ * http请求工具
+ *
  * Created by FSQ
  * CopyRight https://www.fuint.cn
  */