|
@@ -1,6 +1,7 @@
|
|
|
package com.etotem.cfc.service;
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.entity.PackageOrder;
|
|
import com.etotem.cfc.entity.PackageOrder;
|
|
@@ -36,6 +37,7 @@ import java.util.Base64;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -263,6 +265,18 @@ public class PaymentService implements PaymentServiceInterface {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Object> createWechatPrepay(String orderNo, String description, Integer totalFee, String openid) {
|
|
public Map<String, Object> createWechatPrepay(String orderNo, String description, Integer totalFee, String openid) {
|
|
|
|
|
+ return createWechatPrepay(orderNo, description, totalFee, openid, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信 JSAPI 下单(v3 /v3/pay/transactions/jsapi)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param goodsDetail 商品明细列表(微信订单中心展示用),元素为 Map,需包含
|
|
|
|
|
+ * merchant_goods_id / goods_name / quantity / unit_price(单位:分)。
|
|
|
|
|
+ * 传 null 或空列表时不携带 detail 字段。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> createWechatPrepay(String orderNo, String description, Integer totalFee,
|
|
|
|
|
+ String openid, List<Map<String, Object>> goodsDetail) {
|
|
|
try {
|
|
try {
|
|
|
JSONObject body = new JSONObject();
|
|
JSONObject body = new JSONObject();
|
|
|
body.put("appid", appid);
|
|
body.put("appid", appid);
|
|
@@ -280,6 +294,22 @@ public class PaymentService implements PaymentServiceInterface {
|
|
|
amount.put("currency", "CNY");
|
|
amount.put("currency", "CNY");
|
|
|
body.put("amount", amount);
|
|
body.put("amount", amount);
|
|
|
|
|
|
|
|
|
|
+ // 商品明细(微信订单中心展示商品名/数量/单价)
|
|
|
|
|
+ if (goodsDetail != null && !goodsDetail.isEmpty()) {
|
|
|
|
|
+ JSONObject detail = new JSONObject();
|
|
|
|
|
+ JSONArray goodsArr = new JSONArray();
|
|
|
|
|
+ for (Map<String, Object> g : goodsDetail) {
|
|
|
|
|
+ JSONObject item = new JSONObject();
|
|
|
|
|
+ item.put("merchant_goods_id", g.get("merchant_goods_id"));
|
|
|
|
|
+ item.put("goods_name", g.get("goods_name"));
|
|
|
|
|
+ item.put("quantity", g.get("quantity"));
|
|
|
|
|
+ item.put("unit_price", g.get("unit_price"));
|
|
|
|
|
+ goodsArr.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ detail.put("goods_detail", goodsArr);
|
|
|
|
|
+ body.put("detail", detail);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
String respBody = doPost("/v3/pay/transactions/jsapi", body.toJSONString());
|
|
String respBody = doPost("/v3/pay/transactions/jsapi", body.toJSONString());
|
|
|
JSONObject resp = JSON.parseObject(respBody);
|
|
JSONObject resp = JSON.parseObject(respBody);
|
|
|
String prepayId = resp.getString("prepay_id");
|
|
String prepayId = resp.getString("prepay_id");
|