浏览代码

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 年之前
父节点
当前提交
9d953a460f

+ 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);
 }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TeacherClassCourseSchudeleDto.java

@@ -2,6 +2,7 @@ package com.ym.mec.biz.dal.dto;
 
 import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.enums.CourseStatusEnum;
+import com.ym.mec.biz.dal.enums.TeachModeEnum;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.util.Date;
@@ -57,6 +58,15 @@ public class TeacherClassCourseSchudeleDto {
     @ApiModelProperty(value = "上课学生名称")
     private String studentNames;
 
+    private TeachModeEnum teachMode;
+
+    public TeachModeEnum getTeachMode() {
+        return teachMode;
+    }
+
+    public void setTeachMode(TeachModeEnum teachMode) {
+        this.teachMode = teachMode;
+    }
 
     public String getStudentNames() {
         return studentNames;

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -891,6 +891,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
             studentRegistrationService.update(studentRegistration);
 
             ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
+            classGroupStudentMapper.setMusicGroupId(musicGroupId);
             classGroupStudentMapper.setClassGroupId(classGroup.getId());
             classGroupStudentMapper.setUserId(studentRegistration.getUserId());
             classGroupStudentMapper.setCreateTime(date);
@@ -1308,6 +1309,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         List<ClassGroupStudentMapper> classGroupStudentMapperList = new ArrayList<>();
         for (StudentRegistration studentRegistration : studentList) {
             ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
+            classGroupStudentMapper.setMusicGroupId(musicGroupId);
             classGroupStudentMapper.setClassGroupId(classGroup.getId());
             classGroupStudentMapper.setUserId(studentRegistration.getUserId());
             classGroupStudentMapper.setCreateTime(date);

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

@@ -977,7 +977,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){

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

@@ -52,8 +52,8 @@ public class PayServiceImpl implements PayService {
         unionPay.put("orderNo", orderNo);
         unionPay.put("type", "ADAPAY");
 
-        payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, null);
-        unionPay.put("type", "YQPAY");
+       // Map payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, null);
+       // unionPay.put("type", "YQPAY");
         unionPay.put("payMap", payMap);
 
         return unionPay;

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

@@ -120,7 +120,7 @@ public class StudentRechargeServiceImpl extends BaseServiceImpl<String, StudentR
 
 				if ("WXPay".equals(paymentChannel)) {
 					transType = TransTypeEnum.WECHAT;
-				} else if ("Alipay 2.0".equals(paymentChannel)) {
+				} else if ("Alipay".equals(paymentChannel)) {
 					transType = TransTypeEnum.ALIPAY;
 				}
 

+ 15 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -182,7 +182,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             //添加用户现金账户
             sysUserCashAccountDao.insert(new SysUserCashAccount(userId, "CNY"));
 			// 添加用户电子签章账户
-			contractService.register(userId, sysUser.getRealName(), sysUser.getIdCardNo(), sysUser.getPhone());
+			//contractService.register(userId, sysUser.getRealName(), sysUser.getIdCardNo(), sysUser.getPhone());
             //注册到融云
             if(StringUtils.isEmpty(sysUser.getAvatar())){
                 sysUser.setAvatar(sysConfigDao.findConfigValue(SysConfigService.USER_DEFAULT_HEAD_URL));
@@ -510,6 +510,19 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             studentRegistration.setMusicGroupStatus(ClassGroupStudentStatusEnum.NORMAL);
             studentRegistrationDao.update(studentRegistration);
 
+            //获取当前月
+            Integer month = Integer.parseInt(DateUtil.getMonth(nowDate));
+            //获取下次缴费月份
+            List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByMusicGroupId(studentRegistration.getMusicGroupId());
+            List<Integer> months = musicGroupPaymentCalenders.stream().map(e -> e.getPaymentMonth()).collect(Collectors.toList());
+            for (int i = 0; i < months.size(); i++) {
+                if (months.get(i).equals(month)) {
+                    month = i == months.size() - 1 ? months.get(0) : months.get(i + 1);
+                }
+            }
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.MONTH, month);
+
             //加入缴费周期
             MusicGroupStudentFee musicGroupStudentFee = new MusicGroupStudentFee();
             musicGroupStudentFee.setMusicGroupId(studentRegistration.getMusicGroupId());
@@ -517,6 +530,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             musicGroupStudentFee.setCourseFee(musicOneSubjectClassPlan.getFee());
             musicGroupStudentFee.setCreateTime(nowDate);
             musicGroupStudentFee.setUpdateTime(nowDate);
+            musicGroupStudentFee.setNextPaymentDate(DateUtil.getFirstDayOfMonth(calendar.getTime()));
             musicGroupStudentFee.setLatestPaidTime(nowDate);
             musicGroupStudentFee.setSubjectId(studentRegistration.getActualSubjectId());
             musicGroupStudentFee.setPaymentStatus(MusicGroupStudentFee.PaymentStatus.PAID_COMPLETED);

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -887,6 +887,7 @@
         <result property="currentClassTimes" column="current_class_times_"/>
         <result property="totalClassTimes" column="total_class_times_"/>
         <result property="studentNames" column="student_names_"/>
+        <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
     </resultMap>
 
     <sql id="teacherClassCourseScheduleQueryCondition">
@@ -913,6 +914,7 @@
             cs.type_,
             cs.status_,
             cs.actual_teacher_id_,
+            cs.teach_mode_,
             su.username_,
             cg.total_class_times_
         FROM
@@ -938,6 +940,7 @@
             cs.type_,
             cs.status_,
             cs.actual_teacher_id_,
+            cs.teach_mode_,
             su.username_,
             cg.total_class_times_,
             GROUP_CONCAT(IF(sa.status_='NORMAL',ssu.username_,NULL)) student_names_,

+ 11 - 2
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -59,6 +59,7 @@
         <result column="current_grade_" property="grade"/>
         <result column="current_class_" property="clazz"/>
         <result column="actual_subject_id_" property="subject.id"/>
+        <result column="subject_name_" property="subject.name"/>
     </resultMap>
 
     <!-- 根据主键查询一条记录 -->
@@ -320,8 +321,8 @@
     </update>
 
     <select id="queryStudentInfo" resultMap="StudentInfo">
-        SELECT u.*,sr.name_,sr.current_class_,sr.current_grade_,sr.actual_subject_id_,sr.parents_name_ FROM sys_user u left join
-        student_registration sr on u.id_ = sr.user_id_ where u.id_ = #{userId} order by sr.create_time_ desc limit 0,1
+        SELECT u.*,sr.name_,sr.current_class_,sr.current_grade_,sr.actual_subject_id_,sr.parents_name_,s.name_ subject_name_ FROM sys_user u left join
+        student_registration sr on u.id_ = sr.user_id_ left join subject s on sr.actual_subject_id_ = s.id_ where u.id_ = #{userId} order by sr.create_time_ desc limit 0,1
     </select>
 
     <select id="queryByUserIdAndMusicGroupId" resultMap="StudentRegistration">
@@ -452,6 +453,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_

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

@@ -208,6 +208,13 @@ public class MusicGroupController extends BaseController {
         if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
             goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
             for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
+                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
+                    continue;
+                }
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
+                    continue;
+                }
                 orderAmount = orderAmount.add(goodsGroup.getPrice());
                 //团购乐器减免课程费用
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
@@ -289,6 +296,14 @@ public class MusicGroupController extends BaseController {
         if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
             goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
             for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
+                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
+                    continue;
+                }
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
+                    continue;
+                }
+
                 orderAmount = orderAmount.add(goodsGroup.getPrice());
                 //团购乐器减免课程费用
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
@@ -320,7 +335,13 @@ 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://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
+                "测试订单",
+                "测试订单");
 
         studentRegistrationService.reAddOrder(userId, amount, orderNo, (String) payMap.get("type"), courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId(), ApplyOrder);
 

+ 116 - 5
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;
@@ -27,8 +31,11 @@ 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
@@ -106,10 +113,12 @@ public class StudentOrderController extends BaseController {
         //支付中订单存在,更新状态
         if (msg.getResponseType().equals("1") && notifyMap.size() > 0) {
             String tradeState = msg.getCode().equals("88") ? "1" : "0";
+            String channelType = notifyMap.get("channelType").equals("1") ? "WXPay" : (notifyMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
             notifyMap.put("tradeState", tradeState);
             notifyMap.put("totalMoney", notifyMap.get("payAmount"));
             notifyMap.put("merOrderNo", notifyMap.get("merMerOrderNo"));
-            this.updateOrder(notifyMap);
+            notifyMap.put("channelType", channelType);
+            updateOrder(notifyMap);
             msg.setCode("000000");
             msg.setMsg("success");
         }
@@ -132,13 +141,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);
 
@@ -180,6 +215,9 @@ public class StudentOrderController extends BaseController {
             List<Map<String, String>> responseList = JSON.parseObject(responseParameters, List.class);
             for (Map<String, String> response : responseList) {
                 Map<String, String> rpMap = response;
+                String channelType = rpMap.get("channelType").equals("1") ? "WXPay" : (rpMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
+                rpMap.put("channelType", channelType);
+
                 if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
                     updateOrder(rpMap); //更新订单
                 }
@@ -216,7 +254,6 @@ public class StudentOrderController extends BaseController {
         }
     }
 
-
     public void closeOrders(List<String> orderNoList) throws Exception {
         if (orderNoList.size() == 0) {
             return;
@@ -241,7 +278,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 +309,78 @@ 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");
+
+    }
+
+    @Scheduled(cron = "0/5 * * * * ?")
+    public void setSuccessStatus() throws Exception {
+        List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING, "YQPAY");
+
+        String[] statusArr = {"0", "1", "7"};
+        for (StudentPaymentOrder payingOrder : payingOrders) {
+            Map<String, String> rpMap = new HashMap<>();
+            rpMap.put("tradeState", "1");
+            rpMap.put("remarks", "模拟支付成功");
+            rpMap.put("merOrderNo", payingOrder.getOrderNo());
+            rpMap.put("orderNo", payingOrder.getOrderNo());
+            rpMap.put("channelType", "1");
+
+            String channelType = rpMap.get("channelType").equals("1") ? "WXPay" : (rpMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
+            rpMap.put("channelType", channelType);
+            if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
+                updateOrder(rpMap); //更新订单
+            }
+        }
+
+    }
+
 }

+ 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;
     }
 }