| @@ -1,2 +1,5 @@ | |||||
| ALTER TABLE `wx_merchant` | ALTER TABLE `wx_merchant` | ||||
| ADD COLUMN `business_types` json AFTER `business_id`; | |||||
| ADD COLUMN `business_types` json AFTER `business_id`; | |||||
| ALTER TABLE `wx_pay_account` | |||||
| ADD COLUMN `notify_token` varchar(255) COMMENT '回调token' AFTER `notify_url`; | |||||
| @@ -24,6 +24,8 @@ public class WxPayAccount extends TenantEntity { | |||||
| private String merchantApiKey; | private String merchantApiKey; | ||||
| @io.swagger.annotations.ApiModelProperty(value="微信回调,支持3种回调,(1.url/pay 2.url/refund3.url/separate)",name="notifyUrl") | @io.swagger.annotations.ApiModelProperty(value="微信回调,支持3种回调,(1.url/pay 2.url/refund3.url/separate)",name="notifyUrl") | ||||
| private String notifyUrl; | private String notifyUrl; | ||||
| @io.swagger.annotations.ApiModelProperty(value="tt回调token",name="notifyToken") | |||||
| private String notifyToken; | |||||
| @io.swagger.annotations.ApiModelProperty(value="证书本地存放位置",name="certPath") | @io.swagger.annotations.ApiModelProperty(value="证书本地存放位置",name="certPath") | ||||
| private String certPath; | private String certPath; | ||||
| @io.swagger.annotations.ApiModelProperty(value="商户自己的证书",name="merchantCertPath") | @io.swagger.annotations.ApiModelProperty(value="商户自己的证书",name="merchantCertPath") | ||||
| @@ -38,8 +38,10 @@ public class TtOrder extends TenantEntity { | |||||
| private String author; | private String author; | ||||
| @TableField(exist = false) | @TableField(exist = false) | ||||
| private String authorPic; | private String authorPic; | ||||
| @io.swagger.annotations.ApiModelProperty(value="支付类型(1:微信,)",name="type") | |||||
| @io.swagger.annotations.ApiModelProperty(value="支付类型5 头条担保支付",name="type") | |||||
| private Integer type; | private Integer type; | ||||
| @io.swagger.annotations.ApiModelProperty(value="支付渠道:2-支付宝,1-微信,3-银行卡",name="way") | |||||
| private Integer way; | |||||
| @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款",name="paymentType") | @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款",name="paymentType") | ||||
| private Integer paymentType; | private Integer paymentType; | ||||
| @@ -30,7 +30,6 @@ import lombok.extern.slf4j.Slf4j; | |||||
| @Slf4j | @Slf4j | ||||
| public class DouYinPayHelper { | public class DouYinPayHelper { | ||||
| private static final String SALT = "41dcZnKe0RovCfuVEL7IlXFfy206HPVtWJ5q7KJr"; | |||||
| public static String getSign(Map<String, Object> paramsMap) { | public static String getSign(Map<String, Object> paramsMap) { | ||||
| List<String> paramsArr = new ArrayList<>(); | List<String> paramsArr = new ArrayList<>(); | ||||
| @@ -59,7 +58,6 @@ public class DouYinPayHelper { | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| paramsArr.add(SALT); | |||||
| Collections.sort(paramsArr); | Collections.sort(paramsArr); | ||||
| StringBuilder signStr = new StringBuilder(); | StringBuilder signStr = new StringBuilder(); | ||||
| String sep = ""; | String sep = ""; | ||||
| @@ -117,70 +115,6 @@ public class DouYinPayHelper { | |||||
| return SignUtils.encrypt(signStr.toString(),signMethod); | return SignUtils.encrypt(signStr.toString(),signMethod); | ||||
| } | } | ||||
| /** | |||||
| * urlEncode | |||||
| * | |||||
| * @param src | |||||
| * 微信参数 | |||||
| * @return String | |||||
| * @throws UnsupportedEncodingException | |||||
| * 编码错误 | |||||
| */ | |||||
| private static String urlEncode(String src) throws UnsupportedEncodingException { | |||||
| return URLEncoder.encode(src, Charset.forName("UTF-8").name()).replace("+", "%20"); | |||||
| } | |||||
| /** | |||||
| * 组装签名的字段 | |||||
| * | |||||
| * @param params | |||||
| * 参数 | |||||
| * @param urlEncoder | |||||
| * 是否urlEncoder | |||||
| * @return String | |||||
| */ | |||||
| private static String packageSign(Map<String, Object> params, boolean urlEncoder) { | |||||
| // 先将参数以其参数名的字典序升序进行排序 | |||||
| TreeMap<String, Object> sortedParams = new TreeMap<String, Object>(params); | |||||
| // 遍历排序后的字典,字段内容(不包含 key)与支付 SALT 一起进行字典序排序后,使用&符号链接 | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| boolean first = true; | |||||
| for (Entry<String, Object> param : sortedParams.entrySet()) { | |||||
| String value = param.getValue().toString(); | |||||
| if (StringUtils.isBlank(value)) { | |||||
| continue; | |||||
| } | |||||
| if (first) { | |||||
| first = false; | |||||
| } else { | |||||
| sb.append("&"); | |||||
| } | |||||
| if (urlEncoder) { | |||||
| try { | |||||
| value = urlEncode(value); | |||||
| } catch (UnsupportedEncodingException e) { | |||||
| } | |||||
| } | |||||
| sb.append(value); | |||||
| } | |||||
| return sb.toString(); | |||||
| } | |||||
| public static String createSign(Map<String, Object> params, String sercrect) { | |||||
| // 生成签名前先去除sign | |||||
| params.remove("sign"); | |||||
| params.remove("app_id"); | |||||
| params.remove("thirdparty_id"); | |||||
| String stringA = packageSign(params, false); | |||||
| String stringSignTemp = stringA + "&" + sercrect; | |||||
| return HashUtil.md5(stringSignTemp).toUpperCase(); | |||||
| } | |||||
| public static String doPost(String url, Map<String, Object> params) { | public static String doPost(String url, Map<String, Object> params) { | ||||
| return HttpUtil.payPost(url, JSON.toJSONString(params)); | return HttpUtil.payPost(url, JSON.toJSONString(params)); | ||||
| @@ -215,9 +149,10 @@ public class DouYinPayHelper { | |||||
| //订单查询 | //订单查询 | ||||
| public static OrderQueryResult orderQuery(String appId,String secrect,String orderNo,String thirdParytyId) { | |||||
| public static OrderQueryResult orderQuery(String appId,String salt,String orderNo,String thirdParytyId) { | |||||
| Map map = new HashMap(); | Map map = new HashMap(); | ||||
| map.put("app_id",appId); | map.put("app_id",appId); | ||||
| map.put("salt",salt); | |||||
| map.put("out_order_no",orderNo); | map.put("out_order_no",orderNo); | ||||
| // map.put("sign",createSign(map, secrect)); | // map.put("sign",createSign(map, secrect)); | ||||
| map.put("sign",getSign(map)); | map.put("sign",getSign(map)); | ||||
| @@ -13,6 +13,7 @@ public class DouYinCreatePreOrder { | |||||
| private String appId;//小程序 AppID | private String appId;//小程序 AppID | ||||
| private String sercrect;//密钥 | private String sercrect;//密钥 | ||||
| private String salt;// | |||||
| private String outOrderNo;//开发者侧的订单号, 同一小程序下不可重复 | private String outOrderNo;//开发者侧的订单号, 同一小程序下不可重复 | ||||
| private Integer totalAmount;//支付价格; 接口中参数支付金额单位为[分] | private Integer totalAmount;//支付价格; 接口中参数支付金额单位为[分] | ||||
| private String subject;//商品描述; 长度限制 128 字节,不超过 42 个汉字 | private String subject;//商品描述; 长度限制 128 字节,不超过 42 个汉字 | ||||
| @@ -28,6 +29,7 @@ public class DouYinCreatePreOrder { | |||||
| public Map toRequestMap() { | public Map toRequestMap() { | ||||
| Map map = new HashMap(); | Map map = new HashMap(); | ||||
| map.put("app_id", appId); | map.put("app_id", appId); | ||||
| map.put("salt",salt); | |||||
| map.put("out_order_no", outOrderNo); | map.put("out_order_no", outOrderNo); | ||||
| map.put("total_amount", totalAmount); | map.put("total_amount", totalAmount); | ||||
| map.put("subject", subject); | map.put("subject", subject); | ||||
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.dto.OrderSaveDto; | import com.iformall.domain.dto.OrderSaveDto; | ||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxPayAccount; | |||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.domain.po.tt.TtOrder; | import com.iformall.domain.po.tt.TtOrder; | ||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| @@ -28,7 +29,7 @@ public interface TtOrderService { | |||||
| ResultData createPay(TenantEntity tenantEntity,Long orderId, Long memberId, WxAppinfo appinfo); | ResultData createPay(TenantEntity tenantEntity,Long orderId, Long memberId, WxAppinfo appinfo); | ||||
| ResultData updateOrderStatus(TenantEntity tenantInfo, Long orderId, Long memberId, WxAppinfo cAppInfo); | |||||
| ResultData updateOrderStatus(Long orderId, WxAppinfo cAppInfo, WxPayAccount payAccount); | |||||
| boolean isByMember(Long memberId, Long id); | boolean isByMember(Long memberId, Long id); | ||||
| } | } | ||||
| @@ -20,6 +20,7 @@ import com.iformall.mapper.*; | |||||
| import com.iformall.service.TtCUserService; | import com.iformall.service.TtCUserService; | ||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxPayAccountService; | |||||
| import com.iformall.service.tt.TtCouponService; | import com.iformall.service.tt.TtCouponService; | ||||
| import com.iformall.service.tt.TtOrderService; | import com.iformall.service.tt.TtOrderService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -52,6 +53,9 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| @Autowired | @Autowired | ||||
| private WxAppinfoService wxAppinfoService; | private WxAppinfoService wxAppinfoService; | ||||
| @Autowired | |||||
| private WxPayAccountService payAccountService; | |||||
| @Override | @Override | ||||
| public PageInfo<TtOrder> listAsPage(TtOrder record, Integer pageIndex, Integer pageSize) { | public PageInfo<TtOrder> listAsPage(TtOrder record, Integer pageIndex, Integer pageSize) { | ||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> ttOrderMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> ttOrderMapper.findList(record)); | ||||
| @@ -200,6 +204,10 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| if(appInfo == null) { | if(appInfo == null) { | ||||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | ||||
| } | } | ||||
| WxPayAccount payAcount = payAccountService.getById(appInfo.getPayId()); | |||||
| if(payAcount == null){ | |||||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| TtCoupon coupon = ttCouponService.getById(order.getProductId()); | TtCoupon coupon = ttCouponService.getById(order.getProductId()); | ||||
| if (!coupon.getStatus().equals(EnumTtCouponStatus.TTCOUPON_STATUS_SHELFING.getCode())) { | if (!coupon.getStatus().equals(EnumTtCouponStatus.TTCOUPON_STATUS_SHELFING.getCode())) { | ||||
| logger.error("券已经下架了>>>" + order.getProductId()); | logger.error("券已经下架了>>>" + order.getProductId()); | ||||
| @@ -218,7 +226,7 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| return new ResultData(ErrorCode.ORDER_HAD_CANCEL); | return new ResultData(ErrorCode.ORDER_HAD_CANCEL); | ||||
| } else if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){ | } else if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){ | ||||
| logger.info("订单未支付: " + order.toString()); | logger.info("订单未支付: " + order.toString()); | ||||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), appInfo.getSecret(), order.getId().toString(), null); | |||||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAcount.getApiKey(), order.getId().toString(), null); | |||||
| String trade_state = orderQueryResult.getOrderStatus(); | String trade_state = orderQueryResult.getOrderStatus(); | ||||
| if ("PROCESSING".equals(trade_state)) {//处理中 | if ("PROCESSING".equals(trade_state)) {//处理中 | ||||
| return new ResultData(ErrorCode.PAY_ORDER_PAYING); | return new ResultData(ErrorCode.PAY_ORDER_PAYING); | ||||
| @@ -242,6 +250,8 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| } | } | ||||
| DouYinCreatePreOrder preOrder = new DouYinCreatePreOrder(); | DouYinCreatePreOrder preOrder = new DouYinCreatePreOrder(); | ||||
| preOrder.setAppId(appInfo.getAppId()); | preOrder.setAppId(appInfo.getAppId()); | ||||
| preOrder.setSercrect(appInfo.getSecret()); | |||||
| preOrder.setSalt(payAcount.getApiKey()); | |||||
| preOrder.setOutOrderNo(order.getId().toString()); | preOrder.setOutOrderNo(order.getId().toString()); | ||||
| preOrder.setTotalAmount(order.getPayment()); | preOrder.setTotalAmount(order.getPayment()); | ||||
| preOrder.setSubject(coupon.getTitle()); | preOrder.setSubject(coupon.getTitle()); | ||||
| @@ -261,32 +271,18 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ResultData updateOrderStatus(TenantEntity tenantEntity, Long orderId, Long memberId, WxAppinfo appInfo) { | |||||
| public ResultData updateOrderStatus(Long orderId, WxAppinfo appInfo, WxPayAccount payAccount) { | |||||
| TtOrder order = ttOrderMapper.selectById(orderId); | TtOrder order = ttOrderMapper.selectById(orderId); | ||||
| if (null == order) { | if (null == order) { | ||||
| logger.error("pay order, order not allow, orderId: " + orderId); | logger.error("pay order, order not allow, orderId: " + orderId); | ||||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| } | } | ||||
| if(!order.getCUserId().equals(memberId)){ | |||||
| return new ResultData(ErrorCode.ORDER_USER_NOT_MATCH); | |||||
| } | |||||
| TtCUser byId = ttCUserService.getById(memberId, tenantEntity.getTenantId()); | |||||
| // WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(memberId,tenantEntity.getFinalTenantId()); | |||||
| // if ( null == wxCUserBasicInfo) { | |||||
| if ( byId == null) { | |||||
| logger.error("用户不存在."+memberId); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(),"用户不存在."+memberId); | |||||
| } | |||||
| // if (null != wxCUserBasicInfo && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||||
| // return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||||
| // } | |||||
| // WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); | |||||
| if(appInfo == null) { | |||||
| if(appInfo == null || payAccount == null) { | |||||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | ||||
| } | } | ||||
| if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){ | if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){ | ||||
| logger.info("订单支付中: " + order.toString()); | logger.info("订单支付中: " + order.toString()); | ||||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), appInfo.getSecret(), order.getId().toString(), null); | |||||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), order.getId().toString(), null); | |||||
| String trade_state = orderQueryResult.getOrderStatus(); | String trade_state = orderQueryResult.getOrderStatus(); | ||||
| if ("PROCESSING".equals(trade_state)) {//处理中 | if ("PROCESSING".equals(trade_state)) {//处理中 | ||||
| return new ResultData(ErrorCode.PAY_ORDER_PAYING); | return new ResultData(ErrorCode.PAY_ORDER_PAYING); | ||||
| @@ -294,23 +290,28 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| TtOrder orderSuc = new TtOrder(); | TtOrder orderSuc = new TtOrder(); | ||||
| orderSuc.setId(order.getId()); | orderSuc.setId(order.getId()); | ||||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | ||||
| orderSuc.setWay(orderQueryResult.getWay()); | |||||
| // orderSuc.setPaymentTime(orderQueryResult.getPayTime()); | |||||
| logger.info("支付时间格式---"+orderQueryResult.getPayTime()); | |||||
| orderSuc.setUpdateDate(new Date()); | orderSuc.setUpdateDate(new Date()); | ||||
| ttOrderMapper.updateById(orderSuc); | ttOrderMapper.updateById(orderSuc); | ||||
| // return new ResultData(ErrorCode.PAY_ORDER_EXIST,"该订单已经支付,请勿重复支付!"); | // return new ResultData(ErrorCode.PAY_ORDER_EXIST,"该订单已经支付,请勿重复支付!"); | ||||
| return new ResultData(); | |||||
| }else if ("FAIL".equals(trade_state)) {//失败 | }else if ("FAIL".equals(trade_state)) {//失败 | ||||
| // TtOrder orderSuc = new TtOrder(); | // TtOrder orderSuc = new TtOrder(); | ||||
| // orderSuc.setId(order.getId()); | // orderSuc.setId(order.getId()); | ||||
| // orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | // orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | ||||
| // orderSuc.setUpdateDate(new Date()); | // orderSuc.setUpdateDate(new Date()); | ||||
| // ttOrderMapper.updateById(orderSuc); | // ttOrderMapper.updateById(orderSuc); | ||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR,"支付失败"); | |||||
| }else if ("TIMEOUT".equals(trade_state)) {//超时 | }else if ("TIMEOUT".equals(trade_state)) {//超时 | ||||
| TtOrder orderSuc = new TtOrder(); | |||||
| orderSuc.setId(order.getId()); | |||||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||||
| orderSuc.setUpdateDate(new Date()); | |||||
| ttOrderMapper.updateById(orderSuc); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_CLOSED); | |||||
| // TtOrder orderSuc = new TtOrder(); | |||||
| // orderSuc.setId(order.getId()); | |||||
| // orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||||
| // orderSuc.setUpdateDate(new Date()); | |||||
| // ttOrderMapper.updateById(orderSuc); | |||||
| // return new ResultData(ErrorCode.PAY_ORDER_CLOSED); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR,"支付超时"); | |||||
| } | } | ||||
| } | } | ||||
| return new ResultData(); | return new ResultData(); | ||||
| @@ -8,6 +8,7 @@ | |||||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/> | <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/> | ||||
| <result column="product_id" jdbcType="BIGINT" property="productId"/> | <result column="product_id" jdbcType="BIGINT" property="productId"/> | ||||
| <result column="type" jdbcType="TINYINT" property="type"/> | <result column="type" jdbcType="TINYINT" property="type"/> | ||||
| <result column="way" jdbcType="TINYINT" property="way"/> | |||||
| <result column="payment_type" jdbcType="INTEGER" property="paymentType"/> | <result column="payment_type" jdbcType="INTEGER" property="paymentType"/> | ||||
| <result column="payment" jdbcType="INTEGER" property="payment"/> | <result column="payment" jdbcType="INTEGER" property="payment"/> | ||||
| <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/> | <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/> | ||||
| @@ -24,10 +25,10 @@ | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| o.`id`,o.`tenant_id`,o.`parent_tenant_id`,o.`c_user_id`,o.`product_id`,o.`type`,o.`payment_type`,o.`payment`, | |||||
| o.`id`,o.`tenant_id`,o.`parent_tenant_id`,o.`c_user_id`,o.`product_id`,o.`type`,o.`way`,o.`payment_type`,o.`payment`, | |||||
| o.`payment_time`,o.`order_status`,o.`create_date`,o.`update_date`, | o.`payment_time`,o.`order_status`,o.`create_date`,o.`update_date`, | ||||
| u.`nick_name`,u.`phone`, | u.`nick_name`,u.`phone`, | ||||
| c.`title` product_title,c.`coverImg` product_pic, | |||||
| c.`title` product_title,c.`cover_mg` product_pic, | |||||
| m.`name` author,m.`imgUrl` author_pic | m.`name` author,m.`imgUrl` author_pic | ||||
| </sql> | </sql> | ||||
| @@ -57,6 +58,10 @@ | |||||
| and o.`type` = #{type} | and o.`type` = #{type} | ||||
| </if> | </if> | ||||
| <if test=" null != way "> | |||||
| and o.`way` = #{way} | |||||
| </if> | |||||
| <if test=" null != paymentType "> | <if test=" null != paymentType "> | ||||
| and o.`payment_type` = #{paymentType} | and o.`payment_type` = #{paymentType} | ||||
| </if> | </if> | ||||
| @@ -11,6 +11,8 @@ | |||||
| <result column="api_key" jdbcType="VARCHAR" property="apiKey"/> | <result column="api_key" jdbcType="VARCHAR" property="apiKey"/> | ||||
| <result column="merchant_api_key" jdbcType="VARCHAR" property="merchantApiKey"/> | <result column="merchant_api_key" jdbcType="VARCHAR" property="merchantApiKey"/> | ||||
| <result column="notify_url" jdbcType="VARCHAR" property="notifyUrl"/> | <result column="notify_url" jdbcType="VARCHAR" property="notifyUrl"/> | ||||
| <result column="notify_token" jdbcType="VARCHAR" property="notifyToken"/> | |||||
| <result column="cert_path" jdbcType="VARCHAR" property="certPath"/> | <result column="cert_path" jdbcType="VARCHAR" property="certPath"/> | ||||
| <result column="merchant_cert_path" jdbcType="VARCHAR" property="merchantCertPath"/> | <result column="merchant_cert_path" jdbcType="VARCHAR" property="merchantCertPath"/> | ||||
| <result column="type" jdbcType="INTEGER" property="type"/> | <result column="type" jdbcType="INTEGER" property="type"/> | ||||
| @@ -27,7 +29,7 @@ | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`parent_tenant_id`,`mch_id`,`sub_mch_id`,`sub_app_id`,`api_key`,`merchant_api_key`,`notify_url`,`cert_path`, | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`mch_id`,`sub_mch_id`,`sub_app_id`,`api_key`,`merchant_api_key`,`notify_url`,`notify_token`,`cert_path`, | |||||
| `merchant_cert_path`,`type`,`share`,`rate`,`real_rate`, | `merchant_cert_path`,`type`,`share`,`rate`,`real_rate`, | ||||
| `service_id`,`pay_score_notify_url`,`api_v3_key`,`cert_serial_no`,`private_key_path`,`private_cert_path` | `service_id`,`pay_score_notify_url`,`api_v3_key`,`cert_serial_no`,`private_key_path`,`private_cert_path` | ||||
| </sql> | </sql> | ||||
| @@ -1,10 +1,17 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxPayAccount; | |||||
| import com.iformall.douyin.pay.DouYinPayHelper; | |||||
| import com.iformall.interceptor.BodyReaderHttpServletRequestWrapper; | import com.iformall.interceptor.BodyReaderHttpServletRequestWrapper; | ||||
| import com.iformall.service.WxAppinfoService; | |||||
| import com.iformall.service.WxPayAccountService; | |||||
| import com.iformall.service.tt.TtOrderService; | |||||
| import com.iformall.utils.sign.SignUtils; | import com.iformall.utils.sign.SignUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| @@ -17,7 +24,14 @@ public class TtOrderCallbackController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| private final String token = "ttZhiBoTang"; | |||||
| @Autowired | |||||
| private TtOrderService ttOrderService; | |||||
| @Autowired | |||||
| private WxAppinfoService appinfoService; | |||||
| @Autowired | |||||
| private WxPayAccountService payAccountService; | |||||
| /** | /** | ||||
| * timestamp number Unix 时间戳,10 位,整型数 | * timestamp number Unix 时间戳,10 位,整型数 | ||||
| @@ -28,7 +42,7 @@ public class TtOrderCallbackController extends BaseController { | |||||
| * | * | ||||
| * appid string 小程序 id | * appid string 小程序 id | ||||
| * cp_orderno string 开发者传入订单号 | * cp_orderno string 开发者传入订单号 | ||||
| * way string way 字段中标识了支付渠道:2-支付宝,1-微信 | |||||
| * way string way 字段中标识了支付渠道:2-支付宝,1-微信,3-银行卡 | |||||
| * cp_extra string 预下单时开发者传入字段 | * cp_extra string 预下单时开发者传入字段 | ||||
| * | * | ||||
| * @return 支付通知 | * @return 支付通知 | ||||
| @@ -40,33 +54,41 @@ public class TtOrderCallbackController extends BaseController { | |||||
| String body = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | String body = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | ||||
| Map<String, Object> parameterMap = JSONObject.parseObject(body, Map.class); | |||||
| String timestamp = parameterMap.get("timestamp").toString(); | |||||
| String nonce = parameterMap.get("nonce").toString(); | |||||
| String msg = parameterMap.get("msg").toString(); | |||||
| String type = parameterMap.get("type").toString(); | |||||
| String msgSignature = parameterMap.get("msg_signature").toString(); | |||||
| logger.info("timestamp:"+timestamp+",nonce:"+nonce+",msg:"+msg+",type:"+type+",msgSignature:"+msgSignature); | |||||
| Map<String,Object> paramMap = new HashMap<>(); | |||||
| paramMap.put("token",token); | |||||
| paramMap.put("timestamp",timestamp); | |||||
| paramMap.put("nonce",nonce); | |||||
| paramMap.put("msg",msg); | |||||
| String sha = SignUtils.getSign(null, paramMap, "SHA1"); | |||||
| logger.info("sha----"+sha); | |||||
| if(msgSignature.equals(sha)){ | |||||
| logger.info("true"); | |||||
| } | |||||
| try { | try { | ||||
| // resultMap.put("err_no",0); | |||||
| // resultMap.put("err_tips","success"); | |||||
| Map<String, Object> parameterMap = JSONObject.parseObject(body, Map.class); | |||||
| String timestamp = (String) parameterMap.get("timestamp"); | |||||
| String nonce = (String) parameterMap.get("nonce"); | |||||
| // {"appid":"tt9da4eb19029c2bb301","cp_orderno":"557490321114062848","cp_extra":"","way":"2","channel_no":"2021052622001418391405536769","channel_gateway_no":"12105260162116189897","payment_order_no":"2021052622001418391405536769","out_channel_order_no":"","total_amount":100} | |||||
| String msg = (String) parameterMap.get("msg"); | |||||
| String type = (String) parameterMap.get("type"); | |||||
| String msgSignature = (String) parameterMap.get("msg_signature"); | |||||
| if("payment".equals(type)){ | |||||
| Map<String, Object> pMap = JSONObject.parseObject(msg, Map.class); | |||||
| String appid = (String) pMap.get("appid"); | |||||
| String cp_orderno = (String) pMap.get("cp_orderno");//开发者传入订单号 | |||||
| String way = (String) pMap.get("way");//2-支付宝,1-微信 | |||||
| WxAppinfo appinfo = appinfoService.getByAppId(appid); | |||||
| WxPayAccount payAccount = payAccountService.getById(appinfo.getPayId()); | |||||
| Map<String,Object> paramMap = new HashMap<>(); | |||||
| paramMap.put("token",payAccount.getNotifyToken()); | |||||
| paramMap.put("timestamp",timestamp); | |||||
| paramMap.put("nonce",nonce); | |||||
| paramMap.put("msg",msg); | |||||
| String sign = DouYinPayHelper.getTTBackSign(paramMap, "SHA1"); | |||||
| if(msgSignature.equalsIgnoreCase(sign)){ | |||||
| ttOrderService.updateOrderStatus(Long.valueOf(cp_orderno),appinfo,payAccount); | |||||
| resultMap.put("err_no",0); | |||||
| resultMap.put("err_tips","success"); | |||||
| } | |||||
| } | |||||
| return resultMap; | return resultMap; | ||||
| } catch (Exception e){ | } catch (Exception e){ | ||||
| e.printStackTrace(); | e.printStackTrace(); | ||||
| resultMap.put("err_tips","error"); | |||||
| return resultMap; | return resultMap; | ||||
| } | } | ||||
| } | } | ||||
| @@ -35,6 +35,9 @@ public class TtOrderController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxAppinfoService wxAppinfoService; | private WxAppinfoService wxAppinfoService; | ||||
| @Autowired | |||||
| private WxPayAccountService payAccountService; | |||||
| @ApiOperation("分页订单列表接口") | @ApiOperation("分页订单列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @@ -214,8 +217,13 @@ public class TtOrderController extends BaseController { | |||||
| if (cAppInfo == null) { | if (cAppInfo == null) { | ||||
| return new ResultData(ErrorCode.APP_ID_NOT_ENABLE); | return new ResultData(ErrorCode.APP_ID_NOT_ENABLE); | ||||
| } | } | ||||
| WxPayAccount payAccout = payAccountService.getById(cAppInfo.getId()); | |||||
| if (payAccout == null) { | |||||
| return new ResultData(ErrorCode.APP_ID_NOT_ENABLE); | |||||
| } | |||||
| if(code.intValue() == 0){ | if(code.intValue() == 0){ | ||||
| return ttOrderService.updateOrderStatus(getTenantInfo(),orderId,memberId,cAppInfo); | |||||
| return ttOrderService.updateOrderStatus(orderId,cAppInfo,payAccout); | |||||
| }else{ | }else{ | ||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||