Jelajahi Sumber

小程序订阅

李天标 2 tahun lalu
induk
melakukan
2e885ab762

+ 121 - 24
src/main/java/com/szwl/controller/TOrderController.java

@@ -20,9 +20,7 @@ import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.entity.*;
 import com.szwl.model.query.TAdminParam;
-import com.szwl.model.utils.DateUtils;
-import com.szwl.model.utils.JoinpayConstant;
-import com.szwl.model.utils.PushUtils;
+import com.szwl.model.utils.*;
 import com.szwl.service.*;
 import com.szwl.service.es.EsTOrderService;
 import io.swagger.annotations.ApiOperation;
@@ -886,11 +884,11 @@ public class TOrderController {
             }
             JSONObject resultJson = JSONObject.parseObject(result);
             // 返回支付二维码图片
-            String rd_Pic = resultJson.getString("qr_code");
-            String qrcode = toQrcode(rd_Pic);
-            if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
-                return JsonMessage.error("找不到支付图片");
-            }
+//            String rd_Pic = resultJson.getString("qr_code");
+//            String qrcode = toQrcode(rd_Pic);
+//            if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
+//                return JsonMessage.error("找不到支付图片");
+//            }
             JSONObject kindData = new JSONObject();
             kindData.put("sn", sn);
             return JsonMessage.success(kindData.toString());
@@ -908,13 +906,18 @@ public class TOrderController {
             }
             JSONObject resultJson = JSONObject.parseObject(result);
             // 汇聚支付支付申请返回支付二维码图片
-            String rd_Pic = resultJson.getString("rd_Pic");
-            if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
-                return JsonMessage.error("找不到支付图片");
+//            String rd_Pic = resultJson.getString("rd_Pic");
+//            if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
+//                return JsonMessage.error("找不到支付图片");
+//            }
+            if(resultJson.getString("ra_Code").equals("100")){
+                JSONObject kindData = new JSONObject();
+                kindData.put("sn", sn);
+                return JsonMessage.success(kindData.toString());
+            }else {
+                return JsonMessage.error("申请支付失败");
             }
-            JSONObject kindData = new JSONObject();
-            kindData.put("sn", sn);
-            return JsonMessage.success(kindData.toString());
+
         }
 
     }
@@ -1931,6 +1934,11 @@ public class TOrderController {
         List<TPromoCode> promoCodeAll = new ArrayList<>();
 
         TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
+        if(StringUtils.isNotEmpty(equipmentDesc.getStatus())){
+            if(equipmentDesc.getStatus().equals("1")){
+                return JsonMessage.error("设备在做糖,请稍后再进行支付");
+            }
+        }
         if(equipmentDesc==null||equipmentDesc.getEquipmentId()==null||equipmentDesc.getPayType()==null||equipmentDesc.getPayType().equals("0")){
             //1,type=0,原始设定,没有第二件半价
             for (String key : productNameMap.keySet()) {
@@ -2519,12 +2527,11 @@ public class TOrderController {
             } catch (ParseException e) {
                 e.printStackTrace();
             } catch (UnsupportedEncodingException e) {
-
                 e.printStackTrace();
             }
-
             orderService.updateById(order);
-
+            //传送数据
+            sentJingZhun(order);
             JSONObject kindData = new JSONObject();
             kindData.put("sn", order.getSn());
             kindData.put("productName", order.getProductName());
@@ -2535,6 +2542,12 @@ public class TOrderController {
                 JSONObject kindData1 = new JSONObject();
                 kindData1.put("sn", order.getSn());
                 kindData1.put("productDesc", order.getProductDesc());
+                String s = order.getId().toString();
+                if(s.length()>6){
+                    s = s.substring(s.length()-6,s.length());
+                }
+                kindData1.put("mealCode", s);
+                order.setOrderStatus("0");
                 equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("cardPayXCX", kindData1.toString()).toString());
                 TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
                 BigDecimal integral = szsmWx.getIntegral();
@@ -2580,6 +2593,48 @@ public class TOrderController {
 
         return "success";
     }
+//    @RequestMapping(value = "/sentJingZhun", method = RequestMethod.POST)
+//    @ResponseBody
+    private void sentJingZhun( TOrder order) {
+        order = orderService.getById(order.getId());
+        int i = 0;
+        TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
+        if(admin.getId().toString().equals("372")||admin.getRelationAdminId().equals("372")||admin.getId().toString().equals("639")||admin.getId().toString().equals("238")){
+            //发送数据到鲸准
+            String url = "http://47.106.13.109:3000/api/listen";
+            Map<String,String> map = new HashMap<>();
+            map.put("clientId",order.getClientId());
+            map.put("price", String.valueOf(order.getPrice()));
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            map.put("pay_date",sdf.format(order.getPayDate()));
+            if(order.getWxId()!=null){
+                //小程序下单
+                TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
+                map.put("sourceChannel","1");
+                map.put("phone",szsmWx.getPhone());
+                map.put("amount",order.getMarketingAmount().toString());
+                map.put("nickName","1");
+                map.put("uninoId",szsmWx.getOpenId());
+            }else {
+                //机器下单
+                map.put("sourceChannel","0");
+                map.put("phone","");
+                map.put("amount","0");
+                map.put("nickName","");
+                map.put("uninoId","");
+            }
+            TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
+            map.put("latitude", String.valueOf(byClientId.getLatitude()));
+            map.put("longitude", String.valueOf(byClientId.getLongitude()));
+            String data = JSON.toJSONString(map);
+            try {
+                String s = HttpClientSslUtils.doPost(url, data);
+                System.out.println("发送鲸准:"+s);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
 
     /**
      * 支付成功回调  杉德
@@ -2905,12 +2960,12 @@ public class TOrderController {
         String sn = request.getParameter("r2_OrderNo");
         LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
         query.eq(TOrder::getSn,sn);
-        List<TOrder> list = orderService.list();
-        TOrder order = new TOrder();
+        List<TOrder> list = orderService.list(query);
+        TOrder order = list.get(0);
         if (order == null) {
             return "success";
         }
-        if (order.getStatus() != 3) {
+        if (order.getStatus() == 3) {
             return "success";
         }
 
@@ -2919,6 +2974,9 @@ public class TOrderController {
             // 已退款
             order.setStatus(3);
             BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
+            if(order.getRefundMarketingAmount()!=null){
+                r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
+            }
             BigDecimal price = order.getPrice();
             if(r4_refundAmount.compareTo(price)==-1){
                 BigDecimal refundAmount = order.getRefundAmount();
@@ -2926,7 +2984,7 @@ public class TOrderController {
                     order.setRefundAmount(refundAmount.add(r4_refundAmount));
                 }else {
                     // 退款金额
-                    order.setRefundAmount(new BigDecimal(request.getParameter("r4_RefundAmount_str")));
+                    order.setRefundAmount(r4_refundAmount);
                 }
                 order.setStatus(1);
                 order.setPrice(price.subtract(r4_refundAmount));
@@ -2938,17 +2996,31 @@ public class TOrderController {
                     order.setPrice(order.getPrice().add(r4_refundAmount));
                 }else {
                     // 退款金额
-                    order.setRefundAmount(new BigDecimal(request.getParameter("r4_RefundAmount_str")));
+                    order.setRefundAmount(r4_refundAmount);
                 }
             }
             // 退款金额
-            order.setRefundAmount(new BigDecimal(request.getParameter("r4_RefundAmount_str")));
+//            order.setRefundAmount(new BigDecimal(request.getParameter("r4_RefundAmount_str")));
             // 支付平台产生的退款流水号
             String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
             order.setRefundTrxNo(r5_RefundTrxNo);
             order.setRefundDate(new Date());
             order.setModifyDate(new Date());
             orderService.updateById(order);
+            String orderStatus = order.getOrderStatus();
+            if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
+                if(order.getStatus().toString().equals("3")){
+                    TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
+                    JSONObject kindData = new JSONObject();
+                    String s = order.getId().toString();
+                    if(s.length()>6){
+                        s = s.substring(s.length()-6,s.length());
+                    }
+                    kindData.put("mealCode", s);
+                    equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
+
+                }
+            }
             try {
                 esTOrderService.updateDataById(order);
             }catch (Exception e) {
@@ -3098,7 +3170,32 @@ public class TOrderController {
         }
         return JsonMessage.success(sta);
     }
-
+    /**
+     * 上传订单的做糖状态
+     *
+     * @param
+     * @param
+     * @return
+     */
+    @RequestMapping(value = "/sendOrderStatus", method = RequestMethod.GET)
+    @ResponseBody
+    public JsonMessage sendOrderStatus(String sn,String orderStatus) {
+        if(StringUtils.isEmpty(sn)||StringUtils.isEmpty(orderStatus)){
+            return JsonMessage.error("数据有空");
+        }
+        LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
+        query.eq(TOrder::getSn,sn);
+        List<TOrder> list = orderService.list(query);
+        TOrder order = list.get(0);
+        order.setOrderStatus(orderStatus);
+        orderService.updateById(order);
+        if(orderStatus.equals("1")){
+            String s = order.getId().toString();
+            String clientId = order.getClientId();
+            szsmWxService.subscribeMessage(order.getWxId(),s.substring(s.length()-6,s.length()),clientId.substring(clientId.length()-6,clientId.length()));
+        }
+        return JsonMessage.success("success");
+    }
     /**
      * 删除订单
      *

+ 3 - 1
src/main/java/com/szwl/mapper/xml/TSzsmWxMapper.xml

@@ -12,11 +12,13 @@
         <result column="nick_name" property="nickName" />
         <result column="avatar_url" property="avatarUrl" />
         <result column="integral" property="integral" />
+        <result column="if_subscribe" property="ifSubscribe" />
+
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, open_id, create_date, modify_date, phone, nick_name, avatar_url, integral
+        id, open_id, create_date, modify_date, phone, nick_name, avatar_url, integral,if_subscribe
     </sql>
 
 </mapper>

+ 5 - 1
src/main/java/com/szwl/model/entity/TEquipmentDesc.java

@@ -88,6 +88,10 @@ public class TEquipmentDesc implements Serializable {
     @ApiModelProperty(value = "当前机器购物车模式;")
     private String payType;
 
-
+    /**
+     * 机器状态;0:空闲,1:在做糖
+     */
+    @ApiModelProperty(value = "机器状态;0:空闲,1:在做糖;")
+    private String status;
 
 }

+ 3 - 0
src/main/java/com/szwl/model/entity/TOrder.java

@@ -75,6 +75,9 @@ public class TOrder implements Serializable {
 
     private String trxNo;
 
+    //'订单状态;0:排队中,1:正在制作,2:已制作',
+    private String orderStatus;
+
     private String refundTrxNo;
 
     private String es;

+ 2 - 1
src/main/java/com/szwl/model/entity/TSzsmWx.java

@@ -43,5 +43,6 @@ public class TSzsmWx implements Serializable {
     @ApiModelProperty(value = "积分")
     private BigDecimal integral;
 
-
+    //是否订阅取餐通知,0或者null:没有订阅;1:已订阅
+    private String ifSubscribe;
 }

+ 248 - 0
src/main/java/com/szwl/model/utils/HttpClientSslUtils.java

@@ -0,0 +1,248 @@
+package com.szwl.model.utils;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.jboss.logging.MDC;
+import org.springframework.http.HttpStatus;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * HTTP/HTTPS 请求封装: GET / POST
+ * 默认失败重试3次
+ * @author admin
+ */
+@Slf4j
+public class HttpClientSslUtils {
+
+    /**
+     * 默认的字符编码格式
+     */
+    private static final String DEFAULT_CHAR_SET = "UTF-8";
+    /**
+     * 默认连接超时时间 (毫秒)
+     */
+    private static final Integer DEFAULT_CONNECTION_TIME_OUT = 2000;
+    /**
+     * 默认socket超时时间 (毫秒)
+     */
+    private static final Integer DEFAULT_SOCKET_TIME_OUT = 3000;
+
+    /** socketTimeOut上限 */
+    private static final Integer SOCKET_TIME_OUT_UPPER_LIMIT = 10000;
+
+    /** socketTimeOut下限 */
+    private static final Integer SOCKET_TIME_OUT_LOWER_LIMIT = 1000;
+
+    private static CloseableHttpClient getHttpClient() {
+        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(DEFAULT_SOCKET_TIME_OUT)
+                .setConnectTimeout(DEFAULT_CONNECTION_TIME_OUT).build();
+        return HttpClients.custom().setDefaultRequestConfig(requestConfig)
+                .setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
+    }
+
+    private static CloseableHttpClient getHttpClient(Integer socketTimeOut) {
+        RequestConfig requestConfig =
+                RequestConfig.custom().setSocketTimeout(socketTimeOut).setConnectTimeout(DEFAULT_CONNECTION_TIME_OUT)
+                        .build();
+        return HttpClients.custom().setDefaultRequestConfig(requestConfig)
+                .setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
+    }
+
+    public static String doPost(String url, String requestBody) throws Exception {
+        return doPost(url, requestBody, ContentType.APPLICATION_JSON);
+    }
+
+    public static String doPost(String url, String requestBody, Integer socketTimeOut) throws Exception {
+        return doPost(url, requestBody, ContentType.APPLICATION_JSON, null, socketTimeOut);
+    }
+
+    public static String doPost(String url, String requestBody, ContentType contentType) throws Exception {
+        return doPost(url, requestBody, contentType, null);
+    }
+
+    public static String doPost(String url, String requestBody, List<BasicHeader> headers) throws Exception {
+        return doPost(url, requestBody, ContentType.APPLICATION_JSON, headers);
+    }
+
+    public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers)
+            throws Exception {
+        return doPost(url, requestBody, contentType, headers, getHttpClient());
+    }
+
+    public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers,
+                                Integer socketTimeOut) throws Exception {
+        if (socketTimeOut < SOCKET_TIME_OUT_LOWER_LIMIT || socketTimeOut > SOCKET_TIME_OUT_UPPER_LIMIT) {
+            log.error("socketTimeOut非法");
+            throw new Exception();
+        }
+        return doPost(url, requestBody, contentType, headers, getHttpClient(socketTimeOut));
+    }
+
+
+    /**
+     * 通用Post远程服务请求
+     * @param url
+     * 	请求url地址
+     * @param requestBody
+     * 	请求体body
+     * @param contentType
+     * 	内容类型
+     * @param headers
+     * 	请求头
+     * @return String 业务自行解析
+     * @throws Exception
+     */
+    public static String doPost(String url, String requestBody, ContentType contentType, List<BasicHeader> headers,
+                                CloseableHttpClient client) throws Exception {
+
+        // 构造http方法,设置请求和传输超时时间,重试3次
+        CloseableHttpResponse response = null;
+        long startTime = System.currentTimeMillis();
+        try {
+            HttpPost post = new HttpPost(url);
+            if (!CollectionUtils.isEmpty(headers)) {
+                for (BasicHeader header : headers) {
+                    post.setHeader(header);
+                }
+            }
+            StringEntity entity =
+                    new StringEntity(requestBody, ContentType.create(contentType.getMimeType(), DEFAULT_CHAR_SET));
+            post.setEntity(entity);
+            response = client.execute(post);
+            if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
+                log.error("业务请求返回失败:{}", EntityUtils.toString(response.getEntity()));
+                throw new Exception();
+            }
+            String result = EntityUtils.toString(response.getEntity());
+            return result;
+        } finally {
+            releaseResourceAndLog(url, requestBody, response, startTime);
+        }
+    }
+
+    /**
+     * 暂时用于智慧园区业务联调方式
+     * @param url 业务请求url
+     * @param param 业务参数
+     * @return
+     * @throws Exception
+     */
+    public static String doPostWithUrlEncoded(String url,
+                                              Map<String, String> param) throws Exception {
+        // 创建Httpclient对象
+        CloseableHttpClient httpClient = getHttpClient();
+        CloseableHttpResponse response = null;
+        long startTime = System.currentTimeMillis();
+        try {
+            // 创建Http Post请求
+            HttpPost httpPost = new HttpPost(url);
+            // 创建参数列表
+            if (param != null) {
+                List<org.apache.http.NameValuePair> paramList = new ArrayList<>();
+                for (String key : param.keySet()) {
+                    paramList.add(new BasicNameValuePair(key, param.get(key)));
+                }
+                // 模拟表单
+                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList, DEFAULT_CHAR_SET);
+                httpPost.setEntity(entity);
+            }
+            // 执行http请求
+            response = httpClient.execute(httpPost);
+            if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
+                log.error("业务请求返回失败:{}" , EntityUtils.toString(response.getEntity()));
+                throw new Exception();
+            }
+            String resultString = EntityUtils.toString(response.getEntity(), DEFAULT_CHAR_SET);
+            return resultString;
+        } finally {
+            releaseResourceAndLog(url, param == null ? null : param.toString(), response, startTime);
+        }
+    }
+
+    private static void releaseResourceAndLog(String url, String request, CloseableHttpResponse response, long startTime) {
+        if (null != response) {
+            try {
+                response.close();
+                recordInterfaceLog(startTime, url, request);
+            } catch (IOException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+
+    public static String doGet(String url) throws Exception {
+        return doGet(url, ContentType.DEFAULT_TEXT);
+    }
+
+    public static String doGet(String url, ContentType contentType) throws Exception {
+        return doGet(url, contentType, null);
+    }
+
+    public static String doGet(String url, List<BasicHeader> headers) throws Exception {
+        return doGet(url, ContentType.DEFAULT_TEXT, headers);
+    }
+
+    /**
+     * 通用Get远程服务请求
+     * @param url
+     * 	请求参数
+     * @param contentType
+     * 	请求参数类型
+     * @param headers
+     * 	请求头可以填充
+     * @return String 业务自行解析数据
+     * @throws Exception
+     */
+    public static String doGet(String url, ContentType contentType, List<BasicHeader> headers) throws Exception {
+        CloseableHttpResponse response = null;
+        long startTime = System.currentTimeMillis();
+        try {
+            CloseableHttpClient client = getHttpClient();
+            HttpGet httpGet = new HttpGet(url);
+            if (!CollectionUtils.isEmpty(headers)) {
+                for (BasicHeader header : headers) {
+                    httpGet.setHeader(header);
+                }
+            }
+            if(contentType != null){
+                httpGet.setHeader("Content-Type", contentType.getMimeType());
+            }
+            response = client.execute(httpGet);
+            if (response.getStatusLine().getStatusCode() != HttpStatus.OK.value()) {
+                log.error("业务请求返回失败:{}", EntityUtils.toString(response.getEntity()));
+                throw new Exception();
+            }
+            String result = EntityUtils.toString(response.getEntity());
+            return result;
+        } finally {
+            releaseResourceAndLog(url, null, response, startTime);
+        }
+    }
+
+    private static void recordInterfaceLog(long startTime, String url, String request) {
+        long endTime = System.currentTimeMillis();
+        long timeCost = endTime - startTime;
+        MDC.put("totalTime", String.valueOf(timeCost));
+        MDC.put("url", url);
+        MDC.put("logType", "third-platform-service");
+        log.info("HttpClientSslUtils 远程请求:{} 参数:{} 耗时:{}ms", url, request, timeCost);
+    }
+}
+

+ 131 - 0
src/main/java/com/szwl/model/utils/JsonUtil.java

@@ -0,0 +1,131 @@
+package com.szwl.model.utils;
+
+import cn.hutool.core.lang.TypeReference;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+
+import java.text.SimpleDateFormat;
+
+@Slf4j
+public class JsonUtil {
+
+    /**
+     * 定义映射对象
+     */
+    public static ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 日期格式化
+     */
+    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+    static {
+        //对象的所有字段全部列入
+        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+        //取消默认转换timestamps形式
+        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+        //忽略空Bean转json的错误
+        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+        //所有的日期格式都统一为以下的样式,即yyyy-MM-dd HH:mm:ss
+        objectMapper.setDateFormat(new SimpleDateFormat(DATE_FORMAT));
+        //忽略 在json字符串中存在,但是在java对象中不存在对应属性的情况。防止错误
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+    }
+
+    /**
+     * string转JsonNode
+     *
+     * @param jsonString
+     * @return com.fasterxml.jackson.databind.JsonNode
+     */
+    public static JsonNode stringToJsonNode(String jsonString) throws JsonProcessingException {
+
+        return objectMapper.readTree(jsonString);
+
+    }
+
+    /**
+     * 对象转json字符串
+     *
+     * @param obj
+     * @param <T>
+     */
+    public static <T> String objToString(T obj) {
+
+        if (obj == null) {
+            return null;
+        }
+        try {
+            return obj instanceof String ? (String) obj : objectMapper.writeValueAsString(obj);
+        } catch (JsonProcessingException e) {
+            log.warn("Parse Object to String error : {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * 对象转格式化的字符串字符串
+     *
+     * @param obj
+     * @param <T>
+     * @return
+     */
+    public static <T> String objToPrettyString(T obj) {
+        if (obj == null) {
+            return null;
+        }
+        try {
+            return obj instanceof String ? (String) obj : objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
+        } catch (JsonProcessingException e) {
+            log.warn("Parse Object to String error : {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * json字符串转对象
+     *
+     * @param jsonString
+     * @param cls
+     * @param <T>
+     */
+    public static <T> T stringToObj(String jsonString, Class<T> cls) {
+        if (StringUtils.isEmpty(jsonString) || cls == null) {
+            return null;
+        }
+        try {
+            return cls.equals(String.class) ? (T) jsonString : objectMapper.readValue(jsonString, cls);
+        } catch (JsonProcessingException e) {
+            log.warn("Parse String to Object error : {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * json字符串转对象(复杂泛型类型)
+     *
+     * @param jsonString
+     * @param typeReference
+     * @param <T>
+     * @return
+     */
+    public static <T> T stringToObj(String jsonString, TypeReference<T> typeReference) {
+        if (StringUtils.isEmpty(jsonString) || typeReference == null) {
+            return null;
+        }
+        try {
+//            return typeReference.getType().equals(String.class) ? (T) jsonString : objectMapper.readValue(jsonString, typeReference);
+            return null;
+        } catch (Exception e) {
+            log.warn("Parse String to Object error : {}", e.getMessage());
+            return null;
+        }
+    }
+}

+ 1 - 1
src/main/java/com/szwl/service/TSzsmWxService.java

@@ -12,5 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2022-10-23
  */
 public interface TSzsmWxService extends IService<TSzsmWx> {
-
+    public String subscribeMessage(Long id,String code,String clientId);
 }

+ 29 - 3
src/main/java/com/szwl/service/impl/TJoinpayMchServiceImpl.java

@@ -382,10 +382,34 @@ public class TJoinpayMchServiceImpl extends ServiceImpl<TJoinpayMchMapper, TJoin
         data.add(new BasicNameValuePair("q5_OpenId", openId));
         data.add(new BasicNameValuePair("q6_AuthCode", authCode));
         data.add(new BasicNameValuePair("q7_AppId", appid));
-        data.add(new BasicNameValuePair("q8_TerminalNo", ""));
+
+        if(frpCode.equals("ALIPAY_CARD")||frpCode.equals("WEIXIN_CARD")){
+            if(!StringUtils.isEmpty(tradeMerchantNo)){
+                if(tradeMerchantNo.equals("777150700323486")){
+                    data.add(new BasicNameValuePair("q8_TerminalNo", "000001EC"));
+                }else if(tradeMerchantNo.equals("777164600304087")){
+                    data.add(new BasicNameValuePair("q8_TerminalNo", "000001ED"));
+                }else {
+                    data.add(new BasicNameValuePair("q8_TerminalNo", "000001EE"));
+                }
+            }else {
+                data.add(new BasicNameValuePair("q8_TerminalNo", "000001EE"));
+            }
+        }
+//        data.add(new BasicNameValuePair("q8_TerminalNo", ""));
         data.add(new BasicNameValuePair("q9_TransactionModel", transactionModel));
         if(!StringUtils.isEmpty(tradeMerchantNo)){
-            data.add(new BasicNameValuePair("qa_TradeMerchantNo",tradeMerchantNo));
+            if(frpCode.equals("ALIPAY_CARD")||frpCode.equals("WEIXIN_CARD")){
+                if(!StringUtils.isEmpty(tradeMerchantNo)){
+                    data.add(new BasicNameValuePair("qa_TradeMerchantNo",tradeMerchantNo));
+                }else {
+                    data.add(new BasicNameValuePair("qa_TradeMerchantNo","777114600391409"));
+                }
+            }else{
+                data.add(new BasicNameValuePair("qa_TradeMerchantNo",tradeMerchantNo));
+            }
+        }else {
+            data.add(new BasicNameValuePair("qa_TradeMerchantNo","777114600391409"));
         }
 //        data.add(new BasicNameValuePair("qa_TradeMerchantNo", tradeMerchantNo));
         data.add(new BasicNameValuePair("qb_buyerId", buyerId));
@@ -398,7 +422,9 @@ public class TJoinpayMchServiceImpl extends ServiceImpl<TJoinpayMchMapper, TJoin
 
         // TODO: 2019-04-01  空值不参与签名!!!!!!!!!!!!!!!!!!
 
-
+        if(frpCode.equals("ALIPAY_CARD")||frpCode.equals("WEIXIN_CARD")){
+            data.add(new BasicNameValuePair("ql_TerminalIp", "47.112.127.131"));
+        }
         String hmac = createHmacSign(data, JoinpayConstant.key);
         data.add(new BasicNameValuePair("hmac", hmac));
 //        logger.info("请求参数:" + data);

+ 47 - 1
src/main/java/com/szwl/service/impl/TSzsmWxServiceImpl.java

@@ -1,11 +1,18 @@
 package com.szwl.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.szwl.model.entity.TSzsmWx;
 import com.szwl.mapper.TSzsmWxMapper;
+import com.szwl.model.utils.HttpClientSslUtils;
+import com.szwl.model.utils.JsonUtil;
 import com.szwl.service.TSzsmWxService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * <p>
  *  服务实现类
@@ -16,5 +23,44 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class TSzsmWxServiceImpl extends ServiceImpl<TSzsmWxMapper, TSzsmWx> implements TSzsmWxService {
-
+    @Override
+    public String subscribeMessage(Long id,String code,String clientId) {
+        if(id==null){
+            return "error";
+        }
+        TSzsmWx szsmWx = getById(id);
+        //1,获取获取token
+        String accessToken =null;
+        TSzsmWx wx = getById(1);
+        accessToken = wx.getAvatarUrl();
+        String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken;
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("template_id", "NVmdaK4MwygT63ME830pwM6wZt4eufxhBr6jlQ2XXJ4");
+        jsonObject.put("touser", szsmWx.getOpenId());
+        Map<String,String> map = new HashMap<>();
+        //取货码 code
+        map.put("character_string1",code);
+        //取货点 clientId
+        map.put("thing2","设备编号:"+clientId);
+        //温馨提示
+        map.put("thing5","您的商品正在制作中,制作过程大概需要2分钟,请及时取走。");
+        jsonObject.put("data", map);
+        jsonObject.put("miniprogram_state","formal");
+        jsonObject.put("lang","zh_CN");
+        String reqJsonStr = JsonUtil.objToString(jsonObject);
+        JSONObject  result = null;
+        try {
+            result = JSON.parseObject(HttpClientSslUtils.doPost(url, reqJsonStr));
+            if (result != null) {
+                String errmsg = result.getString("errmsg");
+                if(errmsg.equals("ok")){
+                    szsmWx.setIfSubscribe("0");
+                    updateById(szsmWx);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "success";
+    }
 }

+ 2 - 2
src/main/resources/bootstrap.yml

@@ -3,7 +3,7 @@ spring:
     name: pay-server
   profiles:
     # 打包或运行时,换这里:sit测试,prod正式
-    active: sit
+    active: prod
   cloud:
     config:
       name: pay-server
@@ -36,7 +36,7 @@ spring:
   profiles: sit
   #数据库配置
   datasource:
-    url: jdbc:mysql://rm-wz995mu26a1479kz0so.mysql.rds.aliyuncs.com:3306/orderdb
+    url: jdbc:mysql://rm-wz995mu26a1479kz0so.mysql.rds.aliyuncs.com:3306/orderdb-test
     username: root
     password: sunzee@020
     driver-class-name: com.mysql.jdbc.Driver