فهرست منبع

微信与支付宝支付集成

fllmoyu 4 سال پیش
والد
کامیت
ee4013890f

+ 66 - 0
common/src/main/java/com/jpsoft/enterprise/config/AliPayJpsoftConfig.java

@@ -0,0 +1,66 @@
+package com.jpsoft.enterprise.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2021-2-22 9:54
+ */
+@Data
+@ConfigurationProperties(prefix = "alipay")
+@Component
+public class AliPayJpsoftConfig {
+
+    /**
+     * 支付宝网关
+     */
+    private String serviceUrl;
+
+    /**
+     * 应用appid
+     */
+    private String appId;
+
+    /**
+     * 应用私钥
+     */
+    private String privateKey;
+
+    /**
+     * 支付宝公钥
+     */
+    private String zfbPublicKey;
+
+    /**
+     * 编码
+     */
+    private String inputCharset;
+
+    /**
+     * 服务商id
+     */
+    private String mchId;
+
+    /**
+     * 授权token
+     */
+    private String appAuthToken;
+
+    /**
+     * 加密方式
+     */
+    private String signType;
+
+    /**
+     * 支付回调地址
+     */
+    private String notifyUrl;
+
+    /**
+     * 商品描述
+     */
+    private String body;
+
+}

+ 25 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/dao/OrderInfoDAO.java

@@ -0,0 +1,25 @@
+package com.jpsoft.enterprise.modules.base.dao;
+
+import com.jpsoft.enterprise.modules.base.entity.OrderInfo;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-10-17 12:46
+ */
+@Repository
+public interface OrderInfoDAO {
+    int insert(OrderInfo entity);
+    int update(OrderInfo entity);
+    int exist(String id);
+    OrderInfo get(String id);
+    int delete(String id);
+    List<OrderInfo> list();
+    List<OrderInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+
+    OrderInfo findByOutOrderNo(String outTradeNo);
+}

+ 135 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/entity/OrderInfo.java

@@ -0,0 +1,135 @@
+package com.jpsoft.enterprise.modules.base.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-10-17 12:33
+ */
+@Data
+public class OrderInfo {
+
+    private String id;
+
+    @ApiModelProperty(value = "商品描述")
+    private String body;
+
+    @ApiModelProperty(value = "订单费用")
+    private BigDecimal totalFee;
+
+    @ApiModelProperty(value = "支付状态")
+    private Integer payStatus;
+
+    @ApiModelProperty(value = "支付名称")
+    private String payName;
+
+    @ApiModelProperty(value = "支付金额")
+    private BigDecimal payFee;
+
+    @ApiModelProperty(value = "支付时间")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+    private Date payTime;
+
+    @ApiModelProperty(value = "系统订单号")
+    private String outOrderNo;
+
+    @ApiModelProperty(value = "微信订单号")
+    private String transactionId;
+
+    @ApiModelProperty(value = "支付人标识")
+    private String openId;
+
+
+    /**
+     *是否删除
+     */
+    @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+    /**
+     *创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+    /**
+     *创建时间
+     */
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     *更新人
+     */
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+    /**
+     *更新时间
+     */
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "类别")
+    private String type;
+
+    @ApiModelProperty(value = "支付方式(string)")
+    private String payNameStr;
+
+    @ApiModelProperty(value = "退款时间")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+    private Date refundTime;
+
+    @ApiModelProperty(value = "支付金额")
+    private BigDecimal refundFee;
+
+
+    public String getPayNameStr() {
+        if (StringUtils.isBlank(payName)){
+            return "未支付";
+        }
+        else if ("wechat".equals(payName)){
+            return "微信支付";
+        }
+        else if ("alipay".equals(payName)){
+            return "支付宝支付";
+        }
+        else if ("cash".equals(payName)){
+            return "现金";
+        }
+        else if ("transfer".equals(payName)){
+            return "对公转账";
+        }
+        else if ("individual".equals(payName)){
+            return "个人账户";
+        }
+
+        return payNameStr;
+    }
+
+    public String getPayStatusStr() {
+        if (payStatus.equals(10)){
+            return "未支付";
+        }
+        else if (payStatus.equals(20)){
+            return "已支付";
+        }
+        else if (payStatus.equals(30)){
+            return "已关闭";
+        }
+        else{
+            return "已退款";
+        }
+    }
+
+
+}

+ 27 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/service/OrderInfoService.java

@@ -0,0 +1,27 @@
+package com.jpsoft.enterprise.modules.base.service;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.enterprise.modules.base.entity.OrderInfo;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-10-17 12:39
+ */
+public interface OrderInfoService {
+
+    OrderInfo get(String id);
+    boolean exist(String id);
+    int insert(OrderInfo model);
+    int update(OrderInfo model);
+    int delete(String id);
+    List<OrderInfo> list();
+    Page<OrderInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
+
+    OrderInfo findByOutOrderNo(String outTradeNo);
+
+}

+ 86 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/service/impl/OrderInfoServiceImpl.java

@@ -0,0 +1,86 @@
+package com.jpsoft.enterprise.modules.base.service.impl;
+
+import cn.hutool.core.date.DateUtil;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.jpsoft.enterprise.modules.base.dao.OrderInfoDAO;
+import com.jpsoft.enterprise.modules.base.entity.OrderInfo;
+import com.jpsoft.enterprise.modules.base.service.OrderInfoService;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-10-17 12:42
+ */
+@Transactional
+@Component(value = "orderInfoService")
+@Slf4j
+public class OrderInfoServiceImpl implements OrderInfoService {
+    @Resource
+    private OrderInfoDAO orderInfoDAO;
+
+    @Override
+    public OrderInfo get(String id) {
+        return orderInfoDAO.get(id);
+    }
+
+    @Override
+    public int insert(OrderInfo model) {
+
+        return orderInfoDAO.insert(model);
+    }
+
+    @Override
+    public int update(OrderInfo model) {
+        // TODO Auto-generated method stub
+        return orderInfoDAO.update(model);
+    }
+
+
+    @Override
+    public int delete(String id) {
+        // TODO Auto-generated method stub
+        return orderInfoDAO.delete(id);
+    }
+
+    @Override
+    public boolean exist(String id) {
+        // TODO Auto-generated method stub
+        int count = orderInfoDAO.exist(id);
+
+        return count > 0 ? true : false;
+    }
+
+    @Override
+    public List<OrderInfo> list() {
+        // TODO Auto-generated method stub
+        return orderInfoDAO.list();
+    }
+
+
+    @Override
+    public Page<OrderInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
+        Page<OrderInfo> page = PageHelper.startPage(pageNumber, pageSize, count).doSelectPage(() -> {
+            orderInfoDAO.search(searchParams, sortList);
+        });
+
+        return page;
+    }
+
+    @Override
+    public OrderInfo findByOutOrderNo(String outTradeNo) {
+        return orderInfoDAO.findByOutOrderNo(outTradeNo);
+    }
+
+
+}

+ 182 - 0
common/src/main/resources/mapper/base/OrderInfo.xml

@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.enterprise.modules.base.dao.OrderInfoDAO">
+    <resultMap id="OrderInfoMap" type="com.jpsoft.enterprise.modules.base.entity.OrderInfo">
+        <id property="id" column="id_" />
+        <result property="totalFee" column="total_fee" />
+        <result property="body" column="body_" />
+        <result property="payStatus" column="pay_status" />
+        <result property="payName" column="pay_name" />
+        <result property="payFee" column="pay_fee" />
+        <result property="payTime" column="pay_time" />
+        <result property="outOrderNo" column="out_order_no" />
+        <result property="transactionId" column="transaction_id" />
+        <result property="openId" column="open_id" />
+        <result property="delFlag" column="del_flag"/>
+        <result property="createBy" column="create_by" />
+        <result property="createTime" column="create_time" />
+        <result property="updateBy" column="update_by" />
+        <result property="updateTime" column="update_time" />
+        <result property="type" column="type_"/>
+        <result property="refundFee" column="refund_fee"/>
+        <result property="refundTime" column="refund_time"/>
+    </resultMap>
+    <insert id="insert" parameterType="com.jpsoft.enterprise.modules.base.entity.OrderInfo">
+        <!--
+        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+            select sys_guid() from dual
+        </selectKey>
+        -->
+        <![CDATA[
+		insert into base_order_info
+	    (id_,total_fee,body_,pay_status,pay_name,pay_fee,pay_time,out_order_no,transaction_id,open_id,del_flag,create_by,create_time,update_by,update_time,type_,refund_fee,refund_time)
+		values
+		(
+#{id,jdbcType=VARCHAR}
+,#{totalFee,jdbcType=DECIMAL}
+,#{body,jdbcType=VARCHAR}
+,#{payStatus,jdbcType=INTEGER,jdbcType=VARCHAR}
+,#{payName,jdbcType=VARCHAR}
+,#{payFee,jdbcType=DECIMAL }
+,#{payTime,jdbcType=TIMESTAMP }
+,#{outOrderNo,jdbcType=VARCHAR }
+,#{transactionId,jdbcType=VARCHAR }
+,#{openId,jdbcType=VARCHAR}
+,#{delFlag,jdbcType= NUMERIC }
+,#{createBy,jdbcType=VARCHAR}
+,#{createTime,jdbcType= TIMESTAMP }
+,#{updateBy,jdbcType=VARCHAR}
+,#{updateTime,jdbcType= TIMESTAMP }
+,#{type,jdbcType=VARCHAR}
+,#{refundFee,jdbcType=DECIMAL}
+,#{refundTime,jdbcType=TIMESTAMP}
+		)
+	]]>
+    </insert>
+    <delete id="delete" parameterType="string">
+        delete from base_order_info where id_=#{id,jdbcType=VARCHAR}
+    </delete>
+    <update id="update" parameterType="com.jpsoft.enterprise.modules.base.entity.OrderInfo">
+        update base_order_info
+        <set>
+            <if test="totalFee!=null">
+                total_fee=#{totalFee,jdbcType=DECIMAL},
+            </if>
+            <if test="body!=null">
+                body_=#{body,jdbcType=VARCHAR},
+            </if>
+            <if test="payStatus!=null">
+                pay_status=#{payStatus,jdbcType=INTEGER},
+            </if>
+            <if test="payName!=null">
+                pay_name=#{payName,jdbcType=VARCHAR},
+            </if>
+            <if test="payFee!=null">
+                pay_fee=#{payFee,jdbcType=DECIMAL },
+            </if>
+            <if test="payTime!=null">
+                pay_time=#{payTime,jdbcType=TIMESTAMP },
+            </if>
+            <if test="outOrderNo!=null">
+                out_order_no=#{outOrderNo,jdbcType=VARCHAR },
+            </if>
+            <if test="transactionId!=null">
+                transaction_id=#{transactionId,jdbcType=VARCHAR },
+            </if>
+            <if test="openId!=null">
+                open_id=#{openId,jdbcType=VARCHAR },
+            </if>
+            <if test="delFlag!=null">
+                del_flag=#{delFlag,jdbcType= NUMERIC },
+            </if>
+            <if test="createBy!=null">
+                create_by=#{createBy,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime!=null">
+                create_time=#{createTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="updateBy!=null">
+                update_by=#{updateBy,jdbcType=VARCHAR},
+            </if>
+            <if test="updateTime!=null">
+                update_time=#{updateTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="type!=null">
+                type_=#{type,jdbcType= VARCHAR },
+            </if>
+            <if test="refundFee!=null">
+                refund_fee = #{refundFee,jdbcType=DECIMAL}
+            </if>
+            <if test="refundTime != null">
+                refund_time = #{refundTime,jdbcType=TIMESTAMP}
+            </if>
+        </set>
+        where id_=#{id}
+    </update>
+    <select id="get" parameterType="string" resultMap="OrderInfoMap">
+        select * from base_order_info where id_=#{0}
+    </select>
+    <select id="exist" parameterType="string" resultType="int">
+        select count(*) from base_order_info where id_=#{0}
+    </select>
+    <select id="list" resultMap="OrderInfoMap">
+		select * from base_order_info where del_flag = 0
+	</select>
+    <select id="search" parameterType="hashmap" resultMap="OrderInfoMap">
+        <![CDATA[
+			select * from base_order_info
+		]]>
+        <where>
+            del_flag = false
+            <if test="searchParams.outOrderNo != null">
+                and out_order_no like #{searchParams.outOrderNo}
+            </if>
+            <if test="searchParams.payStatus != null">
+                and pay_status = #{searchParams.payStatus}
+            </if>
+            <if test="searchParams.name != null">
+                and name_ like #{searchParams.name}
+            </if>
+            <if test="searchParams.type != null">
+                and type_ = #{searchParams.type}
+            </if>
+            <if test="searchParams.transactionId != null">
+                and transaction_id like #{searchParams.transactionId}
+            </if>
+            <if test="searchParams.beginTime != null">
+                <![CDATA[
+                  and create_time >= #{searchParams.beginTime}
+            ]]>
+            </if>
+            <if test="searchParams.endTime != null">
+                <![CDATA[
+                  and create_time <= #{searchParams.endTime}
+            ]]>
+            </if>
+            <if test="searchParams.payBeginTime != null">
+                <![CDATA[
+                  and pay_time >= #{searchParams.payBeginTime}
+            ]]>
+            </if>
+            <if test="searchParams.payEndTime != null">
+                <![CDATA[
+                  and pay_time <= #{searchParams.payEndTime}
+            ]]>
+            </if>
+        </where>
+        <foreach item="sort" collection="sortList"  open="order by" separator=",">
+            ${sort.name} ${sort.order}
+        </foreach>
+    </select>
+
+    <select id="findByOutOrderNo" resultMap="OrderInfoMap">
+        <![CDATA[
+        select * from base_order_info
+        where del_flag = 0
+        and out_order_no = #{outTradeNo}
+        ]]>
+    </select>
+
+</mapper>

+ 3 - 0
web/src/main/java/com/jpsoft/enterprise/config/WebMvcConfig.java

@@ -79,6 +79,9 @@ public class WebMvcConfig implements WebMvcConfigurer {
 				.excludePathPatterns("/mobile/whisperingWallApi/whisperingWallInfoList")
 				.excludePathPatterns("/mobile/whisperingWallApi/whisperingWallInfoDetail")
 				.excludePathPatterns("/wechat/**")
+				.excludePathPatterns("/wxPay/**")
+				.excludePathPatterns("/aliPay/**")
+
 
         ;
 	}

+ 237 - 0
web/src/main/java/com/jpsoft/enterprise/modules/pay/alipay/AlipayController.java

@@ -0,0 +1,237 @@
+package com.jpsoft.enterprise.modules.pay.alipay;
+
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.AlipayClient;
+import com.alipay.api.DefaultAlipayClient;
+import com.alipay.api.internal.util.AlipaySignature;
+import com.alipay.api.request.AlipaySystemOauthTokenRequest;
+import com.alipay.api.request.AlipayTradeCreateRequest;
+import com.alipay.api.request.AlipayTradePrecreateRequest;
+import com.alipay.api.response.AlipaySystemOauthTokenResponse;
+import com.alipay.api.response.AlipayTradeCreateResponse;
+import com.alipay.api.response.AlipayTradePrecreateResponse;
+import com.ijpay.alipay.AliPayApi;
+import com.jpsoft.enterprise.config.AliPayJpsoftConfig;
+import com.jpsoft.enterprise.modules.base.entity.OrderInfo;
+import com.jpsoft.enterprise.modules.base.service.OrderInfoService;
+import com.jpsoft.enterprise.modules.common.dto.MessageResult;
+import com.jpsoft.enterprise.modules.wechat.vo.UserInfo;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2019-11-26 9:48
+ */
+
+@Slf4j
+@RequestMapping("/aliPay")
+@RestController
+public class AlipayController {
+
+
+    @Autowired
+    private AliPayJpsoftConfig aliPayJpsoftConfig;
+
+    @Autowired
+    private OrderInfoService orderInfoService;
+
+
+    @RequestMapping(value="/payNotify")
+    public String payNotify(HttpServletRequest request) {
+        try {
+            // 获取支付宝POST过来反馈信息
+
+            Map<String, String> params = AliPayApi.toMap(request);
+
+            for (Map.Entry<String, String> entry : params.entrySet()) {
+                System.out.println(entry.getKey() + " = " + entry.getValue());
+            }
+
+            boolean verifyResult = AlipaySignature.rsaCheckV1(params, aliPayJpsoftConfig.getZfbPublicKey(), "UTF-8", "RSA2");
+
+            if (verifyResult) {
+
+
+                OrderInfo orderInfo = orderInfoService.findByOutOrderNo(params.get("out_trade_no"));
+                String payFee = params.get("total_amount");
+                if (orderInfo == null) {
+                    throw new Exception("支付已完成,但未找到此订单号的流水");
+                }
+
+                orderInfo.setUpdateTime(new Date());
+                orderInfo.setUpdateBy(params.get("buyer_logon_id"));
+                orderInfo.setPayName("alipay");
+                orderInfo.setPayStatus(20);
+                orderInfo.setPayFee(new BigDecimal(payFee));
+                orderInfo.setTransactionId(params.get("trade_no"));
+                orderInfo.setPayTime(DateUtil.parse(params.get("gmt_payment")));
+                orderInfoService.update(orderInfo);
+              //  orderLogService.insert2(new OrderLog(orderInfo.getId(),"支付完成",orderInfo.getCreateBy()));
+
+
+                try {
+                    new Thread(() -> {
+
+
+                        try{
+                            //根据订单类型做各自处理
+                          //  orderInfoService.orderNotifyLogical(orderInfo);
+                        }catch (Exception ex){
+                            /*SysLog sysLog = new SysLog();
+                            sysLog.setRemark(ex.getMessage());
+                            sysLog.setData(orderInfo.toString());
+                            sysLog.setPointcut("支付");
+                            sysLog.setCreateTime(new Date());
+                            sysLogService.insert(sysLog);*/
+
+                        }
+
+                    }).start();
+                } catch (Exception e) {
+                    log.error(e.getMessage(), e);
+                }
+
+
+
+                return "success";
+            } else {
+                log.error("notify_url 验证失败");
+                return "failure";
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage(), e);
+            return "failure";
+        }
+    }
+
+
+    @GetMapping(value="findUserInfo/{authCode}")
+    public MessageResult findUserInfo(@PathVariable(name="authCode") String authCode){
+
+        System.out.println("获取支付宝的userId");
+        try{
+
+            AlipayClient alipayClient = new DefaultAlipayClient(aliPayJpsoftConfig.getServiceUrl(),aliPayJpsoftConfig.getAppId(),aliPayJpsoftConfig.getPrivateKey(),"json",aliPayJpsoftConfig.getInputCharset(),aliPayJpsoftConfig.getZfbPublicKey(),aliPayJpsoftConfig.getSignType());
+
+            AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
+            request.setCode(authCode);
+            request.setGrantType("authorization_code");
+
+            AlipaySystemOauthTokenResponse oauthTokenResponse = alipayClient.execute(request);
+
+            System.out.println(oauthTokenResponse.getUserId());
+
+            HashMap<String,Object> dataMap = new HashMap<String,Object>();
+
+            UserInfo userInfo = new UserInfo();
+            userInfo.setOpenid(oauthTokenResponse.getUserId());
+       //     dataMap.put("openId", oauthTokenResponse.getUserId());
+
+         //   HashMap<String,Object> resultMap = new HashMap<String,Object>();
+
+        //    resultMap.put("userInfo", dataMap);
+
+            return new MessageResult(true, "获取支付宝信息成功", userInfo,200);
+        } catch (AlipayApiException e) {
+
+
+
+            //处理异常
+            e.printStackTrace();
+            return new MessageResult(false, "获取支付宝授权失败", "",400);
+        } catch (Exception e) {
+            //处理异常
+            e.printStackTrace();
+            return new MessageResult(false, "获取支付宝授权失败", "",400);
+        }
+    }
+
+
+    @ApiOperation(value = "支付宝扫码支付")
+    @GetMapping("/tradePrecreatePay")
+    public MessageResult tradePrecreatePay(String orderId) {
+
+        MessageResult result = new MessageResult();
+
+        try {
+            AlipayClient alipayClient = new DefaultAlipayClient(aliPayJpsoftConfig.getServiceUrl(), aliPayJpsoftConfig.getAppId(), aliPayJpsoftConfig.getPrivateKey(), "json", aliPayJpsoftConfig.getInputCharset(), aliPayJpsoftConfig.getZfbPublicKey(), aliPayJpsoftConfig.getSignType());
+            AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
+            request.setNotifyUrl(aliPayJpsoftConfig.getNotifyUrl());
+
+            OrderInfo orderInfo = orderInfoService.get(orderId);
+
+            if (orderInfo == null) {
+                throw new Exception("订单不存在");
+            }
+            if (orderInfo.getTotalFee().compareTo(BigDecimal.ZERO) != 1) {
+                throw new Exception("金额有误");
+            }
+            if (orderInfo.getPayStatus() != 10) {
+                throw new Exception("订单状态有误");
+            }
+
+            orderInfoService.update(orderInfo);
+
+            String appAuthToken = aliPayJpsoftConfig.getAppAuthToken();
+
+
+
+
+
+            Map<String, Object> maps = new HashMap<>();
+            maps.put("out_trade_no", orderInfo.getOutOrderNo());
+            maps.put("total_amount", String.valueOf(orderInfo.getTotalFee()));
+            maps.put("subject", orderInfo.getBody());
+            maps.put("timeout_express", "5m");
+
+            JSONObject extendParams = new JSONObject();
+
+            extendParams.put("sys_service_provider_id", aliPayJpsoftConfig.getMchId());
+            maps.put("extend_params", extendParams);
+            request.putOtherTextParam("app_auth_token",appAuthToken);
+            //把订单信息转换为json对象的字符串
+            String postdata = JSONObject.toJSONString(maps);
+            request.setBizContent(postdata);
+            AlipayTradePrecreateResponse response = alipayClient.execute(request);
+            String body = response.getBody();
+            JSONObject jsonObject = JSONObject.parseObject(body);
+            String alipayTradePrecreateResponse = jsonObject.getString("alipay_trade_precreate_response");
+            JSONObject jsonResponse = JSONObject.parseObject(alipayTradePrecreateResponse);
+
+            if (!jsonResponse.getString("code").equals("10000")) {
+                throw new Exception(jsonResponse.getString("sub_msg"));
+            }
+
+            String qr_code = jsonObject.getJSONObject("alipay_trade_precreate_response").getString("qr_code");
+            result.setResult(true);
+
+            log.warn("qr_code=" + qr_code);
+            result.setData(qr_code);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage(), e);
+            result.setResult(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+
+    }
+
+
+}

+ 214 - 0
web/src/main/java/com/jpsoft/enterprise/modules/pay/weixin/WxPayController.java

@@ -0,0 +1,214 @@
+package com.jpsoft.enterprise.modules.pay.weixin;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.ijpay.core.enums.SignType;
+import com.ijpay.core.enums.TradeType;
+import com.ijpay.core.kit.HttpKit;
+import com.ijpay.core.kit.WxPayKit;
+import com.ijpay.wxpay.WxPayApi;
+import com.ijpay.wxpay.model.UnifiedOrderModel;
+import com.jfinal.kit.StrKit;
+import com.jpsoft.enterprise.config.WxJpsoftConfig;
+import com.jpsoft.enterprise.modules.base.entity.OrderInfo;
+import com.jpsoft.enterprise.modules.base.entity.PersonInfo;
+import com.jpsoft.enterprise.modules.base.service.OrderInfoService;
+import com.jpsoft.enterprise.modules.base.service.PersonInfoService;
+import com.jpsoft.enterprise.modules.common.dto.MessageResult;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import net.sf.json.JSONObject;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2019-11-26 10:35
+ */
+
+@RequestMapping("/wxPay")
+@RestController
+@Slf4j
+public class WxPayController {
+
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private WxJpsoftConfig wxJpsoftConfig;
+
+    @Autowired
+    private OrderInfoService orderInfoService;
+
+    @Autowired
+    private PersonInfoService personInfoService;
+
+
+    @Value("${jwt.secret}")
+    private String jwtSecret;
+
+
+    @ApiOperation(value = "微信JSAPI支付公用方法")
+    @GetMapping("/wxJsapiPay")
+    public MessageResult wxJsapiPay(String orderId) {
+        MessageResult msgResult = new MessageResult<>();
+        try {
+            OrderInfo orderInfo = orderInfoService.get(orderId);
+
+            if (orderInfo == null) {
+                throw new Exception("订单不存在");
+            }
+
+
+            String subMchId = wxJpsoftConfig.getSubMchId();
+
+            PersonInfo personInfo = personInfoService.findByOpenId(orderInfo.getOpenId());
+
+            if (personInfo == null) {
+                throw new Exception("订单支付人不存在");
+            }
+
+            if (StrUtil.isBlank(personInfo.getOpenId())) {
+                throw new Exception("openId不存在");
+            }
+            if (orderInfo.getTotalFee().compareTo(BigDecimal.ZERO) != 1) {
+                throw new Exception("金额有误");
+            }
+            if (orderInfo.getPayStatus() != 10) {
+                throw new Exception("订单状态有误");
+            }
+            String outOrderNo = orderInfo.getOutOrderNo();
+            if (StringUtils.isNotBlank(wxJpsoftConfig.getUrlKey()) && !outOrderNo.contains(wxJpsoftConfig.getUrlKey())) {
+                outOrderNo = wxJpsoftConfig.getUrlKey() + outOrderNo;
+                orderInfo.setOutOrderNo(outOrderNo);
+                orderInfoService.update(orderInfo);
+            }
+
+            //金额处理
+            int wxTotalTee = orderInfo.getTotalFee().multiply(new BigDecimal(100)).intValue();
+            Map<String, String> params = UnifiedOrderModel
+                    .builder()
+                    .appid(wxJpsoftConfig.getAppId())
+                    .mch_id(wxJpsoftConfig.getMchId())
+                    .sub_mch_id(subMchId)
+                    //     .sub_appid(wxConfig.getAppId())
+                    .nonce_str(WxPayKit.generateStr())
+                    .body(orderInfo.getBody())
+                    .out_trade_no(orderInfo.getOutOrderNo())
+                    .total_fee(String.valueOf(wxTotalTee))
+                    .spbill_create_ip(wxJpsoftConfig.getIp())
+                    .notify_url(wxJpsoftConfig.getNotifyUrl())
+                    .trade_type(TradeType.JSAPI.getTradeType())
+                    .sub_openid(personInfo.getOpenId())
+                    //    .openid(orderInfo.getOpenId())
+                    .build()
+                    .createSign(wxJpsoftConfig.getMchKey(), SignType.HMACSHA256);
+
+            String xmlResult = WxPayApi.pushOrder(false, params);
+
+            Map<String, String> resultMap = WxPayKit.xmlToMap(xmlResult);
+            String returnCode = resultMap.get("return_code");
+            String returnMsg = resultMap.get("return_msg");
+            if (!WxPayKit.codeIsOk(returnCode)) {
+                logger.error(returnCode);
+                throw new Exception(returnMsg);
+            }
+            String resultCode = resultMap.get("result_code");
+            if (!WxPayKit.codeIsOk(resultCode)) {
+                String errCode = resultMap.get("err_code_des");
+                logger.error(errCode);
+                throw new Exception(errCode);
+            }
+
+            // 以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回
+
+            String prepayId = resultMap.get("prepay_id");
+
+            Map<String, String> packageParams = WxPayKit.prepayIdCreateSign(prepayId, wxJpsoftConfig.getAppId(),
+                    wxJpsoftConfig.getMchKey(), SignType.HMACSHA256);
+
+            msgResult.setData(packageParams);
+            msgResult.setResult(true);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error(e.getMessage(), e);
+            msgResult.setResult(false);
+            msgResult.setMessage(e.getMessage());
+        }
+        return msgResult;
+    }
+
+    @RequestMapping(value = "/wxJsapiPayNotify", method = {RequestMethod.POST, RequestMethod.GET})
+    @ResponseBody
+    public String wxJsapiPayNotify(HttpServletRequest request) {
+        String xmlMsg = HttpKit.readData(request);
+        logger.warn("支付通知=" + xmlMsg);
+        Map<String, String> params = WxPayKit.xmlToMap(xmlMsg);
+
+        String returnCode = params.get("return_code");
+        String outTradeNo = params.get("out_trade_no");
+        String payTimeStr = params.get("time_end");
+        Date payTime = DateUtil.parse(payTimeStr);
+
+        // 注意此处签名方式需与统一下单的签名类型一致 WxPayApiConfigKit.getWxPayApiConfig().getPartnerKey()
+        if (WxPayKit.verifyNotify(params, wxJpsoftConfig.getMchKey(), SignType.HMACSHA256)) {
+            if (WxPayKit.codeIsOk(returnCode)) {
+                // 更新订单信息
+
+                try {
+                    OrderInfo orderInfo = orderInfoService.findByOutOrderNo(outTradeNo);
+                    if (orderInfo == null) {
+                        throw new Exception("支付已完成,但未找到此订单号的流水");
+                    }
+                    if (orderInfo.getTotalFee().multiply(new BigDecimal(100)).compareTo(new BigDecimal(params.get("total_fee"))) != 0) {
+                        throw new Exception("支付金额与系统金额不一致");
+                    }
+
+                    orderInfo.setUpdateTime(new Date());
+                    orderInfo.setUpdateBy(params.get("openid"));
+                    orderInfo.setPayName("wechat");
+                    orderInfo.setPayStatus(20);
+                    orderInfo.setPayFee(new BigDecimal(params.get("total_fee")).divide(new BigDecimal(100)));
+                    orderInfo.setTransactionId(params.get("transaction_id"));
+                    orderInfo.setPayTime(payTime);
+                    orderInfoService.update(orderInfo);
+                    //    orderLogService.insert2(new OrderLog(orderInfo.getId(), "支付完成", orderInfo.getCreateBy()));
+
+                    new Thread(() -> {
+                        try {
+                            //根据订单类型做各自处理
+                          //  orderInfoService.orderNotifyLogical(orderInfo);
+                        } catch (Exception ex) {
+
+                        }
+                    }).start();
+
+                    // 发送通知等
+                    Map<String, String> xml = new HashMap<String, String>(2);
+                    xml.put("return_code", "SUCCESS");
+                    xml.put("return_msg", "OK");
+                    return WxPayKit.toXml(xml);
+                } catch (Exception e) {
+                    logger.error(e.getMessage(), e);
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+}