Jelajahi Sumber

开启缴费批量更新缴费状态

周箭河 5 tahun lalu
induk
melakukan
005c732312

+ 18 - 3
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRegistrationDao.java

@@ -3,6 +3,7 @@ package com.ym.mec.biz.dal.dao;
 import java.util.List;
 import java.util.Map;
 
+import com.ym.mec.biz.dal.entity.MusicGroup;
 import org.apache.ibatis.annotations.Param;
 
 import com.ym.mec.auth.api.entity.SysUser;
@@ -64,7 +65,7 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
      * @param musicGroupId
      * @return
      */
-     List<MusicGroupSubjectPlan> getNoClassStuCountByMusicGroupId(@Param("musicGroupId") String musicGroupId);
+    List<MusicGroupSubjectPlan> getNoClassStuCountByMusicGroupId(@Param("musicGroupId") String musicGroupId);
 
     /**
      * 根据乐团id和user_id 更新
@@ -186,12 +187,14 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
 
     /**
      * 乐团添加学员
+     *
      * @param studentRegistration
      */
     void insertBasic(StudentRegistration studentRegistration);
 
     /**
      * 获取乐团已缴费学员列表
+     *
      * @param musicGroupId
      * @return
      */
@@ -199,6 +202,7 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
 
     /**
      * 统计乐团不同声部报名人数
+     *
      * @param musicGroupId
      * @return
      */
@@ -206,21 +210,32 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
 
     /**
      * 根据家长手机号获取用户编号
+     *
      * @param parentPhones
      * @return
      */
     List<Map<Integer, String>> findParentId(String parentPhones);
-    
+
     /**
      * 查询学生数
+     *
      * @return
      */
-    Map<String,Integer> queryStudentNum(@Param("organId") Integer organId);
+    Map<String, Integer> queryStudentNum(@Param("organId") Integer organId);
 
     /**
      * 根据乐团编号获取当前乐团所有已报名学员
+     *
      * @param musicGroupId
      * @return
      */
     List<Map<Integer, String>> findMapByMusicGroupId(String musicGroupId);
+
+    /**
+     * 乐团开启缴费
+     * @param musicGroupId
+     * @param paymentStatus
+     * @return
+     */
+    int musicGroupOpenPay(@Param("musicGroupId") String musicGroupId, @Param("paymentStatus") PaymentStatusEnum paymentStatus);
 }

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -984,7 +984,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         musicGroup.setApplyExpireDate(DateUtil.toDate(expireDate));
         musicGroup.setStatus(MusicGroupStatusEnum.PAY);
         musicGroupDao.update(musicGroup);
-        //乐团成立后(开始缴费)
+        //所有人开启缴费
+        studentRegistrationDao.musicGroupOpenPay(musicGroupId,PaymentStatusEnum.OPEN);
         //获取所有已报名学员列表
         HashMap<Integer,String> map = JSONObject.parseObject(JSONObject.toJSONString(MapUtil.convertMybatisMap(studentRegistrationDao.findMapByMusicGroupId(musicGroupId))), HashMap.class);
         if(map != null && map.size() > 0){

+ 8 - 0
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -452,6 +452,14 @@
         update_time_ = now()
         WHERE FIND_IN_SET(id_,#{ids}) AND payment_status_ = '0'
     </update>
+
+    <!-- 乐团批量开启缴费 -->
+    <update id="musicGroupOpenPay">
+        UPDATE student_registration
+        SET payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+        update_time_ = now()
+        WHERE music_group_id_ = #{musicGroupId} AND payment_status_ = '0'
+    </update>
     
     <select id="queryStudentNum" resultType="map">
         SELECT count(sr.id_) total_num_,sum(case when sr.create_time_ >= timestamp(date_add(curdate(), interval - day(curdate()) + 1 day)) then 1 else 0 end) new_num_,sum(case when sr.music_group_status_ = 'QUIT' and sr.update_time_ >= timestamp(date_add(curdate(), interval - day(curdate()) + 1 day)) then 1 else 0 end) quit_num_ FROM student_registration sr left join music_group mg on sr.music_group_id_ = mg.id_

+ 1 - 1
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

@@ -320,7 +320,7 @@ public class MusicGroupController extends BaseController {
 
         String orderNo = idGeneratorService.generatorId("payment") + "";
 
-        Map payMap = payService.getPayMap(orderAmount, orderNo, "http://47.99.212.176:8000/studentOrder/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
+        Map payMap = payService.getPayMap(orderAmount, orderNo, "http://mstudev.dayaedu.com/api-student/studentOrder/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
 
         studentRegistrationService.reAddOrder(userId, amount, orderNo, (String) payMap.get("type"), courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId(), ApplyOrder);
 

+ 91 - 6
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -11,12 +11,16 @@ import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.biz.service.StudentRegistrationService;
 import com.ym.mec.biz.service.VipGroupService;
 import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.thirdparty.adapay.NotifyEvent;
 import com.ym.mec.thirdparty.adapay.Pay;
 import com.ym.mec.thirdparty.yqpay.Msg;
 import com.ym.mec.thirdparty.yqpay.YqPayUtil;
 import com.ym.mec.thirdparty.yqpay.YqPayFeignService;
 import com.ym.mec.thirdparty.yqpay.RsqMsg;
+import com.ym.mec.util.http.HttpUtil;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
@@ -25,10 +29,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
-
 import java.math.BigDecimal;
+import java.net.URLEncoder;
 import java.util.*;
 
+import static com.netflix.config.DeploymentContext.ContextKey.appId;
+
 @RequestMapping("studentOrder")
 @Api(tags = "订单回调")
 @RestController
@@ -109,7 +115,8 @@ public class StudentOrderController extends BaseController {
             notifyMap.put("tradeState", tradeState);
             notifyMap.put("totalMoney", notifyMap.get("payAmount"));
             notifyMap.put("merOrderNo", notifyMap.get("merMerOrderNo"));
-            this.updateOrder(notifyMap);
+            notifyMap.put("channelType", notifyMap.get("channelType"));
+            updateOrder(notifyMap);
             msg.setCode("000000");
             msg.setMsg("success");
         }
@@ -132,13 +139,39 @@ public class StudentOrderController extends BaseController {
 
     @ApiOperation(value = "台牌支付")
     @PostMapping("/executePayment")
-    public Object executePayment(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String payChannel, String sign) throws Exception {
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "amount", value = "支付金额", required = true, dataType = "BigDecimal"),
+            @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "payChannel", value = "支付方式(alipay-支付宝app支付)", required = true, dataType = "String"),
+    })
+    public Object executePayment(BigDecimal amount, String orderNo, String payChannel, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sign,String code) throws Exception {
+        String appId = "wxcf8e8b33a9477845";
+        String appSecret = "1286452b9c68b13325dece7cdf892645";
+        String wxMpOAuth2AccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
         payChannel = PayChannelEnum.ALIPAY_QR.getCode();
 //        if (!new Pay().verifySign(amount, orderNo, notifyUrl, orderSubject, orderBody,sign)) {
 //            return failed("签名验证失败");
 //        }
-        Payment payment = new Pay().executePayment(amount, orderNo, payChannel, orderSubject, orderBody);
+
+        String openid="";
+        if(payChannel=="wx_pub"){
+            if(code==null || code.isEmpty()){
+                return failed("微信支付请先授权");
+            }
+            wxMpOAuth2AccessTokenUrl = String.format(wxMpOAuth2AccessTokenUrl, appId, appSecret, code);
+            Map<String, String> weChatRes = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
+            if(!weChatRes.containsKey("openid")){
+                return failed("授权失败,请重新授权");
+            }
+            openid = weChatRes.get("openid");
+        }
+
         StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(orderNo);
+        if(order == null){
+            return failed("订单不存在");
+        }
+
+        Payment payment = new Pay().executePayment(amount, orderNo, payChannel, orderSubject, orderBody,code);
         order.setTransNo(payment.getId());
         studentPaymentOrderService.update(order);
 
@@ -216,7 +249,6 @@ public class StudentOrderController extends BaseController {
         }
     }
 
-
     public void closeOrders(List<String> orderNoList) throws Exception {
         if (orderNoList.size() == 0) {
             return;
@@ -241,7 +273,7 @@ public class StudentOrderController extends BaseController {
 
     }
 
-    @Scheduled(cron = "0/5 * * * * ?")
+   // @Scheduled(cron = "0/5 * * * * ?")
     public void adaPayQuery() throws Exception {
         List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING, "ADAPAY");
 
@@ -272,4 +304,57 @@ public class StudentOrderController extends BaseController {
     }
 
 
+    @PostMapping("/adaNotify")
+    public void adaNotify(@ModelAttribute NotifyEvent notifyEvent) throws Exception {
+        logger.info(notifyEvent.toString());
+        if (notifyEvent.getType().equals("payment.success") && notifyEvent.getType().equals("payment.failed")) {
+            return;
+        }
+
+        Map<String, String> notifyMap = JSON.parseObject(notifyEvent.getData(), Map.class);
+
+        //支付中订单存在,更新状态
+        if (notifyMap.size() > 0) {
+            String tradeState = notifyEvent.getType().equals("payment.success") ? "1" : "0";
+            notifyMap.put("tradeState", tradeState);
+            notifyMap.put("totalMoney", notifyMap.get("pay_amt"));
+            notifyMap.put("merOrderNo", notifyMap.get("order_no"));
+            notifyMap.put("merOrderNo", notifyMap.get("order_no"));
+            notifyMap.put("remarks", notifyMap.get("description"));
+            updateOrder(notifyMap);
+        }
+    }
+
+
+    @GetMapping("/authorize")
+    public String authorize(@RequestParam("returnUrl") String returnUrl) {
+        String appId = "wxcf8e8b33a9477845";
+        String url = URLEncoder.encode("http://wxwechat.utools.club/studentOrder/userInfo");
+
+        String redirectURL = String.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect",
+                appId, url);
+
+        return "redirect:" + redirectURL;
+    }
+
+    @GetMapping("/userInfo")
+    public Object userInfo(@RequestParam("code") String code,
+                           @RequestParam("state") String returnUrl) throws Exception {
+        String appId = "wxcf8e8b33a9477845";
+        String appSecret = "1286452b9c68b13325dece7cdf892645";
+
+        String wxMpOAuth2AccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
+
+        wxMpOAuth2AccessTokenUrl = String.format(wxMpOAuth2AccessTokenUrl, appId, appSecret, code);
+
+        Map<String, String> map = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
+
+        if(!map.containsKey("openid")){
+            return failed("授权失败,请重新授权");
+        }
+
+        return map.get("openid");
+
+    }
+
 }

+ 56 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/NotifyEvent.java

@@ -0,0 +1,56 @@
+package com.ym.mec.thirdparty.adapay;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class NotifyEvent {
+    private String id;
+    private String type;
+    private String created_time;
+    private String prod_mode;
+    private String data;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getCreated_time() {
+        return created_time;
+    }
+
+    public void setCreated_time(String created_time) {
+        this.created_time = created_time;
+    }
+
+    public String getProd_mode() {
+        return prod_mode;
+    }
+
+    public void setProd_mode(String prod_mode) {
+        this.prod_mode = prod_mode;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this);
+    }
+}

+ 46 - 39
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Pay.java

@@ -9,6 +9,7 @@ import com.huifu.adapay.exception.BaseAdaPayException;
 import com.huifu.adapay.model.DeviceInfo;
 import com.huifu.adapay.model.payment.*;
 import com.huifu.adapay.util.AdaPaySign;
+import org.aspectj.apache.bcel.classfile.Module;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -18,9 +19,11 @@ import java.util.*;
  */
 public class Pay {
     private static final String appId = "app_7d87c043-aae3-4357-9b2c-269349a980d6";
+    private static final String wxAppId = "wxcf8e8b33a9477845";
 
     /**
      * 运行支付类接口
+     *
      * @return paymentId
      * @throws Exception 异常
      */
@@ -32,7 +35,7 @@ public class Pay {
         //公钥
         String pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB";
         //私钥
-        String privateKey= "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMQhsygJ2pp4nCiDAXiqnZm6AzKSVAh+C0BgGR6QaeXzt0TdSi9VR0OQ7Qqgm92NREB3ofobXvxxT+wImrDNk6R6lnHPMTuJ/bYpm+sx397rPboRAXpV3kalQmbZ3P7oxtEWOQch0zV5B1bgQnTvxcG3REAsdaUjGs9Xvg0iDS2tAgMBAAECgYAqGFmNdF/4234Yq9V7ApOE1Qmupv1mPTdI/9ckWjaAZkilfSFY+2KqO8bEiygo6xMFCyg2t/0xDVjr/gTFgbn4KRPmYucGG+FzTRLH0nVIqnliG5Ekla6a4gwh9syHfstbOpIvJR4DfldicZ5n7MmcrdEwSmMwXrdinFbIS/P1+QJBAOr6NpFtlxVSGzr6haH5FvBWkAsF7BM0CTAUx6UNHb+RCYYQJbk8g3DLp7/vyio5uiusgCc04gehNHX4laqIdl8CQQDVrckvnYy+NLz+K/RfXEJlqayb0WblrZ1upOdoFyUhu4xqK0BswOh61xjZeS+38R8bOpnYRbLf7eoqb7vGpZ9zAkEAobhdsA99yRW+WgQrzsNxry3Ua1HDHaBVpnrWwNjbHYpDxLn+TJPCXvI7XNU7DX63i/FoLhOucNPZGExjLYBH/wJATHNZQAgGiycjV20yicvgla8XasiJIDP119h4Uu21A1Su8G15J2/9vbWn1mddg1pp3rwgvxhw312oInbHoFMxsQJBAJlyDDu6x05MeZ2nMor8gIokxq2c3+cnm4GYWZgboNgq/BknbIbOMBMoe8dJFj+ji3YNTvi1MSTDdSDqJuN/qS0=";
+        String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMQhsygJ2pp4nCiDAXiqnZm6AzKSVAh+C0BgGR6QaeXzt0TdSi9VR0OQ7Qqgm92NREB3ofobXvxxT+wImrDNk6R6lnHPMTuJ/bYpm+sx397rPboRAXpV3kalQmbZ3P7oxtEWOQch0zV5B1bgQnTvxcG3REAsdaUjGs9Xvg0iDS2tAgMBAAECgYAqGFmNdF/4234Yq9V7ApOE1Qmupv1mPTdI/9ckWjaAZkilfSFY+2KqO8bEiygo6xMFCyg2t/0xDVjr/gTFgbn4KRPmYucGG+FzTRLH0nVIqnliG5Ekla6a4gwh9syHfstbOpIvJR4DfldicZ5n7MmcrdEwSmMwXrdinFbIS/P1+QJBAOr6NpFtlxVSGzr6haH5FvBWkAsF7BM0CTAUx6UNHb+RCYYQJbk8g3DLp7/vyio5uiusgCc04gehNHX4laqIdl8CQQDVrckvnYy+NLz+K/RfXEJlqayb0WblrZ1upOdoFyUhu4xqK0BswOh61xjZeS+38R8bOpnYRbLf7eoqb7vGpZ9zAkEAobhdsA99yRW+WgQrzsNxry3Ua1HDHaBVpnrWwNjbHYpDxLn+TJPCXvI7XNU7DX63i/FoLhOucNPZGExjLYBH/wJATHNZQAgGiycjV20yicvgla8XasiJIDP119h4Uu21A1Su8G15J2/9vbWn1mddg1pp3rwgvxhw312oInbHoFMxsQJBAJlyDDu6x05MeZ2nMor8gIokxq2c3+cnm4GYWZgboNgq/BknbIbOMBMoe8dJFj+ji3YNTvi1MSTDdSDqJuN/qS0=";
 
         //设置AdaPay全局参数,不同环境设置不同的apiKey/pubKey/privateKey
         AdaPay.apiKey = apiKeyLive;
@@ -45,16 +48,16 @@ public class Pay {
         AdaPay.startNotifyListener();
     }
 
-    public static String executePaymentTest() throws Exception{
+    public static String executePaymentTest() throws Exception {
         //test chargeId = "002112019080716223300005091372336111616";
         Pay demo = new Pay();
         //支付接口
-        String orderNo = "jsdk_payment_"+System.currentTimeMillis();
+        String orderNo = "jsdk_payment_" + System.currentTimeMillis();
         String payChannel = PayChannelEnum.ALIPAY_QR.getCode();
         BigDecimal amount = new BigDecimal("0.01");
         String orderSubject = "测试大雅订单";
         String orderBody = "测试大雅订单";
-        Payment payment = demo.executePayment(amount,orderNo,payChannel,orderSubject,orderBody);
+        Payment payment = demo.executePayment(amount, orderNo, payChannel, orderSubject, orderBody,null);
         //支付查询接口
         //demo.queryPayment(payment.getId());
         //关单接口
@@ -67,38 +70,41 @@ public class Pay {
     public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String orderSubject, String orderBody) throws Exception {
 
         Map<String, Object> paymentParams = new HashMap<>(10);
-        paymentParams.put("appId",appId);
+        paymentParams.put("appId", appId);
         paymentParams.put("amount", amount);
         paymentParams.put("orderNo", orderNo);
         paymentParams.put("notifyUrl", notifyUrl);
         paymentParams.put("orderSubject", orderSubject);
         paymentParams.put("orderBody", orderBody);
+        paymentParams.put("wxAppId", wxAppId);
         String originalStr = JSONObject.toJSONString(paymentParams);
 
-        String sign  =  AdaPaySign.sign(originalStr, AdaPay.privateKey);
-        paymentParams.put("sign",sign);
+        String sign = AdaPaySign.sign(originalStr, AdaPay.privateKey);
+        paymentParams.put("sign", sign);
+        paymentParams.put("host", "http://192.168.3.27:8000/api-student/studentOrder/executePayment");
         paymentParams.remove(appId);
-        return  paymentParams;
+        return paymentParams;
     }
 
     public boolean verifySign(BigDecimal amount, String orderNo, String notifyUrl, String orderSubject, String orderBody, String sign) throws Exception {
         Map<String, Object> paymentParams = new HashMap<>(10);
-        paymentParams.put("appId",appId);
+        paymentParams.put("appId", appId);
         paymentParams.put("amount", amount);
         paymentParams.put("orderNo", orderNo);
         paymentParams.put("notifyUrl", notifyUrl);
         paymentParams.put("orderSubject", orderSubject);
         paymentParams.put("orderBody", orderBody);
         String originalStr = JSONObject.toJSONString(paymentParams);
-        return AdaPaySign.verifySign(originalStr,sign, AdaPay.pubKey);
+        return AdaPaySign.verifySign(originalStr, sign, AdaPay.pubKey);
     }
 
     /**
      * 执行一个支付交易
+     *
      * @return 创建的支付对象
      * @throws Exception 异常
      */
-    public static Payment executePayment(BigDecimal amount,String orderNo,String payChannel,String orderSubject,String orderBody) throws Exception {
+    public static Payment executePayment(BigDecimal amount, String orderNo, String payChannel, String orderSubject, String orderBody, String openid) throws Exception {
         System.out.println("=======execute payment begin=======");
         //创建支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id3
         Map<String, Object> paymentParams = new HashMap<>(10);
@@ -110,29 +116,28 @@ public class Pay {
         paymentParams.put("goods_title", orderSubject);
         paymentParams.put("goods_desc", orderBody);
 
-        DeviceInfo deviceInfo = new DeviceInfo();
-        deviceInfo.setDeviceType(DeviceTypeEnum.MOBILE.getCode());
-        deviceInfo.setDeviceIp("127.0.0.1");
-        paymentParams.put("device_info", deviceInfo);
-
-        List<GoodsDetail> goodsDetailList = new ArrayList<>();
-        GoodsDetail goodsDetail = new GoodsDetail();
-        goodsDetail.setGoodsId("your goods id");
-        goodsDetail.setGoodsName("your goods name");
-        goodsDetail.setQuantity("1");
-        goodsDetail.setPrice("100.00");
-        goodsDetailList.add(goodsDetail);
-
-        PromotionDetail promotionDetail = new PromotionDetail();
-        promotionDetail.setGoodsDetail(goodsDetailList);
-        promotionDetail.setCostPrice("100.00");
-
-        PaymentExpend expend = new PaymentExpend();
-        expend.setPromotionDetail(promotionDetail);
-        expend.setBuyerId("2088012928900274");
-        expend.setBuyerLogonId("");
-
-        paymentParams.put("expend", expend);
+//        DeviceInfo deviceInfo = new DeviceInfo();
+//        deviceInfo.setDeviceType(DeviceTypeEnum.MOBILE.getCode());
+//        deviceInfo.setDeviceIp("127.0.0.1");
+//        paymentParams.put("device_info", deviceInfo);
+
+//        List<GoodsDetail> goodsDetailList = new ArrayList<>();
+//        GoodsDetail goodsDetail = new GoodsDetail();
+//        goodsDetail.setGoodsId("your goods id");
+//        goodsDetail.setGoodsName("your goods name");
+//        goodsDetail.setQuantity("1");
+//        goodsDetail.setPrice("100.00");
+//        goodsDetailList.add(goodsDetail);
+//
+//        PromotionDetail promotionDetail = new PromotionDetail();
+//        promotionDetail.setGoodsDetail(goodsDetailList);
+//        promotionDetail.setCostPrice("100.00");
+
+        if (openid != null && !openid.isEmpty()) {
+            PaymentExpend expend = new PaymentExpend();
+            expend.setOpenId(openid);
+            paymentParams.put("expend", expend);
+        }
 
         //调用sdk方法,创建支付,得到支付对象
         Payment payment = null;
@@ -141,17 +146,18 @@ public class Pay {
         } catch (BaseAdaPayException e) {
             e.printStackTrace();
         }
-        System.out.println("payment result="+JSON.toJSONString(payment));
+        System.out.println("payment result=" + JSON.toJSONString(payment));
         return payment;
     }
 
     /**
      * 关闭一个支付交易
+     *
      * @param paymentId 要关闭的支付id
      * @return 关闭的支付对象
      * @throws Exception 异常
      */
-    public Payment closePayment(String paymentId) throws Exception{
+    public Payment closePayment(String paymentId) throws Exception {
         System.out.println("=======close payment begin=======");
         //关闭支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id11
         //调用sdk方法,关闭支付,得到支付对象
@@ -161,17 +167,18 @@ public class Pay {
         } catch (BaseAdaPayException e) {
             e.printStackTrace();
         }
-        System.out.println("close payment result="+JSON.toJSONString(payment));
+        System.out.println("close payment result=" + JSON.toJSONString(payment));
         return payment;
     }
 
     /**
      * 查询一个支付交易
+     *
      * @param paymentId 要查询的支付id
      * @return 查询的支付对象
      * @throws Exception 异常
      */
-    public Payment queryPayment(String paymentId) throws Exception{
+    public Payment queryPayment(String paymentId) throws Exception {
         System.out.println("=======query payment begin=======");
         //查询支付对象的参数,全部参数请参考 https://docs.adapay.tech/api/04-trade.html#id7
         //调用sdk方法,查询支付交易,得到支付对象
@@ -181,7 +188,7 @@ public class Pay {
         } catch (BaseAdaPayException e) {
             e.printStackTrace();
         }
-        System.out.println("query payment result="+JSON.toJSONString(payment));
+        System.out.println("query payment result=" + JSON.toJSONString(payment));
         return payment;
     }
 }