dev-discount
袁野 3 years ago
parent 4a84cb915a
commit cd4181bffe
  1. 1
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 1
      hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java
  3. 81
      hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java
  4. 6
      hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java
  5. 2
      hai-cweb/src/main/resources/dev/config.properties
  6. 9
      hai-service/src/main/java/com/hai/config/CommonSysConfig.java
  7. 52
      hai-service/src/main/java/com/hai/config/TelConfig.java
  8. 17
      hai-service/src/main/java/com/hai/dao/OutRechargeOrderMapper.java
  9. 14
      hai-service/src/main/java/com/hai/dao/OutRechargeOrderSqlProvider.java
  10. 15
      hai-service/src/main/java/com/hai/dao/OutRechargePriceMapper.java
  11. 14
      hai-service/src/main/java/com/hai/dao/OutRechargePriceSqlProvider.java
  12. 26
      hai-service/src/main/java/com/hai/entity/OutRechargeOrder.java
  13. 60
      hai-service/src/main/java/com/hai/entity/OutRechargeOrderExample.java
  14. 18
      hai-service/src/main/java/com/hai/entity/OutRechargePrice.java
  15. 60
      hai-service/src/main/java/com/hai/entity/OutRechargePriceExample.java
  16. 163
      hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java
  17. 1
      hai-service/src/main/resources/dev/commonConfig.properties

@ -115,6 +115,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/tuanyou/*")
.excludePathPatterns("/common/*")
.excludePathPatterns("/order/qzOrderToPay")
.excludePathPatterns("/czOrder/orderRefundNotify")
.excludePathPatterns("/tPig/*")
;
}

@ -88,6 +88,7 @@ public class OutRechargeOrderController {
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
if (StringUtils.isBlank(outRechargeOrder.getRechargeContent()) ||
outRechargeOrder.getPayPrice() == null ||
outRechargeOrder.getObjectId() == null ||
outRechargeOrder.getOrderPrice() == null
) {
log.error("addOrder error!");

@ -0,0 +1,81 @@
package com.cweb.controller.pay;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.security.AESEncodeUtil;
import com.hai.config.CommonSysConst;
import com.hai.config.WxOrderConfig;
import com.hai.dao.HighGasOrderRefundMapper;
import com.hai.entity.HighGasOrderRefund;
import com.hai.entity.HighOrder;
import com.hai.entity.OutRechargeOrder;
import com.hai.model.OrderRefundModel;
import com.hai.service.OutRechargeOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Date;
@Controller
@RequestMapping(value = "/czOrder")
@Api(value = "充值回调")
public class CzOrderController {
private static Logger log = LoggerFactory.getLogger(TuanYouController.class);
@Resource
private HighGasOrderRefundMapper highGasOrderRefundMapper;
@Resource
private OutRechargeOrderService outRechargeOrderService;
@RequestMapping(value = "/orderRefundNotify", method = RequestMethod.POST)
@ApiOperation(value = "充值回调")
@ResponseBody
public void orderRefundNotify(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
try {
log.info(reqBodyStr);
HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund();
highGasOrderRefund.setCreateTime(new Date());
highGasOrderRefund.setReturnContent(reqBodyStr);
highGasOrderRefundMapper.insert(highGasOrderRefund);
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);
String dataStr = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(dataObject.getString("data")), CommonSysConst.getSysConfig().getTuanYouAppSecret());
JSONObject object = JSONObject.parseObject(dataStr);
// 查询订单
OutRechargeOrder order = outRechargeOrderService.findByOrderNo(object.getString("orderNumber"));
// 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6.充值失败
if (order != null && order.getStatus() == 5) {
// 退单结果 true:成功 false:失败
if (object.getInteger("rechargeState") == 1 && order != null) {
order.setStatus(3);
outRechargeOrderService.updateOrder(order);
} else if (object.getInteger("rechargeState") == 0 && order != null) {
order.setStatus(6);
outRechargeOrderService.updateOrder(order);
}
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("success");
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
}

@ -118,15 +118,15 @@ public class WechatPayController {
try {
WxSharingReceiversVO receiversVO = new WxSharingReceiversVO();
receiversVO.setAccount("1604968055");
receiversVO.setAccount("1611202250");
receiversVO.setType("MERCHANT_ID");
receiversVO.setName("个体户方涛");
receiversVO.setName("重庆众卡汇电子商务有限公司");
receiversVO.setRelation_type("SERVICE_PROVIDER");
Map<String , String> map = new HashMap<>();
map.put("mch_id" , "1289663601");
map.put("sub_mch_id" , "1609882817");
map.put("sub_mch_id" , "1607303848");
map.put("appid" , "wx637bd6f7314daa46");
map.put("nonce_str" , WxUtils.makeNonStr());
map.put("sign_type" , "HMAC-SHA256");

@ -1,4 +1,4 @@
# ΢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
# \u03A2\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
wxAppId=wx8d49e2f83025229d
wxAppSecret=d8d6dcaef77d3b659258a01b5ddba5df

@ -27,6 +27,15 @@ public class CommonSysConfig {
private String telApiSecret;
private String telMemberId;
private String telUrl;
private String czOrderNotify;
public String getCzOrderNotify() {
return czOrderNotify;
}
public void setCzOrderNotify(String czOrderNotify) {
this.czOrderNotify = czOrderNotify;
}
public String getQinzhuMobileUrl() {
return qinzhuMobileUrl;

@ -3,7 +3,13 @@ package com.hai.config;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.MD5Util;
import com.hai.entity.OutRechargeOrder;
import com.hai.entity.OutRechargePrice;
import com.hai.service.OutRechargeOrderService;
import com.hai.service.OutRechargePriceService;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -18,6 +24,12 @@ import java.util.Map;
public class TelConfig {
@Resource
private OutRechargeOrderService outRechargeOrderService;
@Resource
private OutRechargePriceService outRechargePriceService;
public static JSONObject getMemberGoods() throws Exception {
Map<String,Object> map = new HashMap<>();
@ -32,4 +44,44 @@ public class TelConfig {
return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTelUrl()+ "/getMemberGoods", map);
}
public static JSONObject order(Map<String,Object> mapOrder) throws Exception {
Map<String,Object> map = new HashMap<>();
Long time = new Date().getTime();
String sign = CommonSysConst.getSysConfig().getTelApiSecret() + "_" + time;
for (Map.Entry<String, Object> entry : mapOrder.entrySet()) {
map.put(entry.getKey(), entry.getValue().toString());
}
map.put("apiKey", CommonSysConst.getSysConfig().getTelApiKey());
map.put("memberId", CommonSysConst.getSysConfig().getTelMemberId());
map.put("time", time);
map.put("sign", MD5Util.encode(sign.getBytes()).toLowerCase());
return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTelUrl()+ "/getMemberGoods", map);
}
public static JSONObject checkingOrder(Map<String,Object> mapOrder) throws Exception {
Map<String,Object> map = new HashMap<>();
Long time = new Date().getTime();
String sign = CommonSysConst.getSysConfig().getTelApiSecret() + "_" + time;
for (Map.Entry<String, Object> entry : mapOrder.entrySet()) {
map.put(entry.getKey(), entry.getValue().toString());
}
map.put("apiKey", CommonSysConst.getSysConfig().getTelApiKey());
map.put("memberId", CommonSysConst.getSysConfig().getTelMemberId());
map.put("time", time);
map.put("sign", MD5Util.encode(sign.getBytes()).toLowerCase());
return HttpsUtils.doGet(CommonSysConst.getSysConfig().getTelUrl()+ "/order", map);
}
}

@ -50,7 +50,8 @@ public interface OutRechargeOrderMapper extends OutRechargeOrderMapperExt {
"cancel_time, finish_time, ",
"remarks, out_refund_no, ",
"refund_time, refund_id, ",
"refund_fee, agent_key)",
"refund_fee, agent_key, ",
"object_id)",
"values (#{orderNo,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, ",
"#{userName,jdbcType=VARCHAR}, #{userPhone,jdbcType=VARCHAR}, ",
"#{rechargeModel,jdbcType=INTEGER}, #{payType,jdbcType=INTEGER}, ",
@ -62,7 +63,8 @@ public interface OutRechargeOrderMapper extends OutRechargeOrderMapperExt {
"#{cancelTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP}, ",
"#{remarks,jdbcType=VARCHAR}, #{outRefundNo,jdbcType=VARCHAR}, ",
"#{refundTime,jdbcType=TIMESTAMP}, #{refundId,jdbcType=VARCHAR}, ",
"#{refundFee,jdbcType=DECIMAL}, #{agentKey,jdbcType=VARCHAR})"
"#{refundFee,jdbcType=DECIMAL}, #{agentKey,jdbcType=VARCHAR}, ",
"#{objectId,jdbcType=BIGINT})"
})
@Options(useGeneratedKeys=true,keyProperty="id")
int insert(OutRechargeOrder record);
@ -97,7 +99,8 @@ public interface OutRechargeOrderMapper extends OutRechargeOrderMapperExt {
@Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="refund_id", property="refundId", jdbcType=JdbcType.VARCHAR),
@Result(column="refund_fee", property="refundFee", jdbcType=JdbcType.DECIMAL),
@Result(column="agent_key", property="agentKey", jdbcType=JdbcType.VARCHAR)
@Result(column="agent_key", property="agentKey", jdbcType=JdbcType.VARCHAR),
@Result(column="object_id", property="objectId", jdbcType=JdbcType.BIGINT)
})
List<OutRechargeOrder> selectByExample(OutRechargeOrderExample example);
@ -106,7 +109,7 @@ public interface OutRechargeOrderMapper extends OutRechargeOrderMapperExt {
"id, order_no, user_id, user_name, user_phone, recharge_model, pay_type, pay_price, ",
"order_price, pay_real_price, pay_serial_no, `status`, recharge_content, recharge_name, ",
"id_card, create_timed, pay_time, cancel_time, finish_time, remarks, out_refund_no, ",
"refund_time, refund_id, refund_fee, agent_key",
"refund_time, refund_id, refund_fee, agent_key, object_id",
"from out_recharge_order",
"where id = #{id,jdbcType=BIGINT}"
})
@ -135,7 +138,8 @@ public interface OutRechargeOrderMapper extends OutRechargeOrderMapperExt {
@Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="refund_id", property="refundId", jdbcType=JdbcType.VARCHAR),
@Result(column="refund_fee", property="refundFee", jdbcType=JdbcType.DECIMAL),
@Result(column="agent_key", property="agentKey", jdbcType=JdbcType.VARCHAR)
@Result(column="agent_key", property="agentKey", jdbcType=JdbcType.VARCHAR),
@Result(column="object_id", property="objectId", jdbcType=JdbcType.BIGINT)
})
OutRechargeOrder selectByPrimaryKey(Long id);
@ -173,7 +177,8 @@ public interface OutRechargeOrderMapper extends OutRechargeOrderMapperExt {
"refund_time = #{refundTime,jdbcType=TIMESTAMP},",
"refund_id = #{refundId,jdbcType=VARCHAR},",
"refund_fee = #{refundFee,jdbcType=DECIMAL},",
"agent_key = #{agentKey,jdbcType=VARCHAR}",
"agent_key = #{agentKey,jdbcType=VARCHAR},",
"object_id = #{objectId,jdbcType=BIGINT}",
"where id = #{id,jdbcType=BIGINT}"
})
int updateByPrimaryKey(OutRechargeOrder record);

@ -124,6 +124,10 @@ public class OutRechargeOrderSqlProvider {
sql.VALUES("agent_key", "#{agentKey,jdbcType=VARCHAR}");
}
if (record.getObjectId() != null) {
sql.VALUES("object_id", "#{objectId,jdbcType=BIGINT}");
}
return sql.toString();
}
@ -158,6 +162,7 @@ public class OutRechargeOrderSqlProvider {
sql.SELECT("refund_id");
sql.SELECT("refund_fee");
sql.SELECT("agent_key");
sql.SELECT("object_id");
sql.FROM("out_recharge_order");
applyWhere(sql, example, false);
@ -275,6 +280,10 @@ public class OutRechargeOrderSqlProvider {
sql.SET("agent_key = #{record.agentKey,jdbcType=VARCHAR}");
}
if (record.getObjectId() != null) {
sql.SET("object_id = #{record.objectId,jdbcType=BIGINT}");
}
applyWhere(sql, example, true);
return sql.toString();
}
@ -308,6 +317,7 @@ public class OutRechargeOrderSqlProvider {
sql.SET("refund_id = #{record.refundId,jdbcType=VARCHAR}");
sql.SET("refund_fee = #{record.refundFee,jdbcType=DECIMAL}");
sql.SET("agent_key = #{record.agentKey,jdbcType=VARCHAR}");
sql.SET("object_id = #{record.objectId,jdbcType=BIGINT}");
OutRechargeOrderExample example = (OutRechargeOrderExample) parameter.get("example");
applyWhere(sql, example, true);
@ -414,6 +424,10 @@ public class OutRechargeOrderSqlProvider {
sql.SET("agent_key = #{agentKey,jdbcType=VARCHAR}");
}
if (record.getObjectId() != null) {
sql.SET("object_id = #{objectId,jdbcType=BIGINT}");
}
sql.WHERE("id = #{id,jdbcType=BIGINT}");
return sql.toString();

@ -41,10 +41,10 @@ public interface OutRechargePriceMapper extends OutRechargePriceMapperExt {
@Insert({
"insert into out_recharge_price (`type`, price, ",
"real_price, create_time, ",
"goods_id, discount)",
"goods_id, discount, channel)",
"values (#{type,jdbcType=INTEGER}, #{price,jdbcType=DECIMAL}, ",
"#{realPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP}, ",
"#{goodsId,jdbcType=BIGINT}, #{discount,jdbcType=REAL})"
"#{goodsId,jdbcType=BIGINT}, #{discount,jdbcType=REAL}, #{channel,jdbcType=BIGINT})"
})
@Options(useGeneratedKeys=true,keyProperty="id")
int insert(OutRechargePrice record);
@ -61,13 +61,14 @@ public interface OutRechargePriceMapper extends OutRechargePriceMapperExt {
@Result(column="real_price", property="realPrice", jdbcType=JdbcType.DECIMAL),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="goods_id", property="goodsId", jdbcType=JdbcType.BIGINT),
@Result(column="discount", property="discount", jdbcType=JdbcType.REAL)
@Result(column="discount", property="discount", jdbcType=JdbcType.REAL),
@Result(column="channel", property="channel", jdbcType=JdbcType.BIGINT)
})
List<OutRechargePrice> selectByExample(OutRechargePriceExample example);
@Select({
"select",
"id, `type`, price, real_price, create_time, goods_id, discount",
"id, `type`, price, real_price, create_time, goods_id, discount, channel",
"from out_recharge_price",
"where id = #{id,jdbcType=BIGINT}"
})
@ -78,7 +79,8 @@ public interface OutRechargePriceMapper extends OutRechargePriceMapperExt {
@Result(column="real_price", property="realPrice", jdbcType=JdbcType.DECIMAL),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="goods_id", property="goodsId", jdbcType=JdbcType.BIGINT),
@Result(column="discount", property="discount", jdbcType=JdbcType.REAL)
@Result(column="discount", property="discount", jdbcType=JdbcType.REAL),
@Result(column="channel", property="channel", jdbcType=JdbcType.BIGINT)
})
OutRechargePrice selectByPrimaryKey(Long id);
@ -98,7 +100,8 @@ public interface OutRechargePriceMapper extends OutRechargePriceMapperExt {
"real_price = #{realPrice,jdbcType=DECIMAL},",
"create_time = #{createTime,jdbcType=TIMESTAMP},",
"goods_id = #{goodsId,jdbcType=BIGINT},",
"discount = #{discount,jdbcType=REAL}",
"discount = #{discount,jdbcType=REAL},",
"channel = #{channel,jdbcType=BIGINT}",
"where id = #{id,jdbcType=BIGINT}"
})
int updateByPrimaryKey(OutRechargePrice record);

@ -52,6 +52,10 @@ public class OutRechargePriceSqlProvider {
sql.VALUES("discount", "#{discount,jdbcType=REAL}");
}
if (record.getChannel() != null) {
sql.VALUES("channel", "#{channel,jdbcType=BIGINT}");
}
return sql.toString();
}
@ -68,6 +72,7 @@ public class OutRechargePriceSqlProvider {
sql.SELECT("create_time");
sql.SELECT("goods_id");
sql.SELECT("discount");
sql.SELECT("channel");
sql.FROM("out_recharge_price");
applyWhere(sql, example, false);
@ -113,6 +118,10 @@ public class OutRechargePriceSqlProvider {
sql.SET("discount = #{record.discount,jdbcType=REAL}");
}
if (record.getChannel() != null) {
sql.SET("channel = #{record.channel,jdbcType=BIGINT}");
}
applyWhere(sql, example, true);
return sql.toString();
}
@ -128,6 +137,7 @@ public class OutRechargePriceSqlProvider {
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
sql.SET("goods_id = #{record.goodsId,jdbcType=BIGINT}");
sql.SET("discount = #{record.discount,jdbcType=REAL}");
sql.SET("channel = #{record.channel,jdbcType=BIGINT}");
OutRechargePriceExample example = (OutRechargePriceExample) parameter.get("example");
applyWhere(sql, example, true);
@ -162,6 +172,10 @@ public class OutRechargePriceSqlProvider {
sql.SET("discount = #{discount,jdbcType=REAL}");
}
if (record.getChannel() != null) {
sql.SET("channel = #{channel,jdbcType=BIGINT}");
}
sql.WHERE("id = #{id,jdbcType=BIGINT}");
return sql.toString();

@ -139,15 +139,10 @@ public class OutRechargeOrder implements Serializable {
*/
private String agentKey;
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
/**
* 商品订单
*/
private Long objectId;
private static final long serialVersionUID = 1L;
@ -351,6 +346,14 @@ public class OutRechargeOrder implements Serializable {
this.agentKey = agentKey;
}
public Long getObjectId() {
return objectId;
}
public void setObjectId(Long objectId) {
this.objectId = objectId;
}
@Override
public boolean equals(Object that) {
if (this == that) {
@ -387,7 +390,8 @@ public class OutRechargeOrder implements Serializable {
&& (this.getRefundTime() == null ? other.getRefundTime() == null : this.getRefundTime().equals(other.getRefundTime()))
&& (this.getRefundId() == null ? other.getRefundId() == null : this.getRefundId().equals(other.getRefundId()))
&& (this.getRefundFee() == null ? other.getRefundFee() == null : this.getRefundFee().equals(other.getRefundFee()))
&& (this.getAgentKey() == null ? other.getAgentKey() == null : this.getAgentKey().equals(other.getAgentKey()));
&& (this.getAgentKey() == null ? other.getAgentKey() == null : this.getAgentKey().equals(other.getAgentKey()))
&& (this.getObjectId() == null ? other.getObjectId() == null : this.getObjectId().equals(other.getObjectId()));
}
@Override
@ -419,6 +423,7 @@ public class OutRechargeOrder implements Serializable {
result = prime * result + ((getRefundId() == null) ? 0 : getRefundId().hashCode());
result = prime * result + ((getRefundFee() == null) ? 0 : getRefundFee().hashCode());
result = prime * result + ((getAgentKey() == null) ? 0 : getAgentKey().hashCode());
result = prime * result + ((getObjectId() == null) ? 0 : getObjectId().hashCode());
return result;
}
@ -453,6 +458,7 @@ public class OutRechargeOrder implements Serializable {
sb.append(", refundId=").append(refundId);
sb.append(", refundFee=").append(refundFee);
sb.append(", agentKey=").append(agentKey);
sb.append(", objectId=").append(objectId);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();

@ -1735,6 +1735,66 @@ public class OutRechargeOrderExample {
addCriterion("agent_key not between", value1, value2, "agentKey");
return (Criteria) this;
}
public Criteria andObjectIdIsNull() {
addCriterion("object_id is null");
return (Criteria) this;
}
public Criteria andObjectIdIsNotNull() {
addCriterion("object_id is not null");
return (Criteria) this;
}
public Criteria andObjectIdEqualTo(Long value) {
addCriterion("object_id =", value, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdNotEqualTo(Long value) {
addCriterion("object_id <>", value, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdGreaterThan(Long value) {
addCriterion("object_id >", value, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdGreaterThanOrEqualTo(Long value) {
addCriterion("object_id >=", value, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdLessThan(Long value) {
addCriterion("object_id <", value, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdLessThanOrEqualTo(Long value) {
addCriterion("object_id <=", value, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdIn(List<Long> values) {
addCriterion("object_id in", values, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdNotIn(List<Long> values) {
addCriterion("object_id not in", values, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdBetween(Long value1, Long value2) {
addCriterion("object_id between", value1, value2, "objectId");
return (Criteria) this;
}
public Criteria andObjectIdNotBetween(Long value1, Long value2) {
addCriterion("object_id not between", value1, value2, "objectId");
return (Criteria) this;
}
}
/**

@ -49,6 +49,11 @@ public class OutRechargePrice implements Serializable {
*/
private Float discount;
/**
* 提供商编号
*/
private Long channel;
private static final long serialVersionUID = 1L;
public Long getId() {
@ -107,6 +112,14 @@ public class OutRechargePrice implements Serializable {
this.discount = discount;
}
public Long getChannel() {
return channel;
}
public void setChannel(Long channel) {
this.channel = channel;
}
@Override
public boolean equals(Object that) {
if (this == that) {
@ -125,7 +138,8 @@ public class OutRechargePrice implements Serializable {
&& (this.getRealPrice() == null ? other.getRealPrice() == null : this.getRealPrice().equals(other.getRealPrice()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getGoodsId() == null ? other.getGoodsId() == null : this.getGoodsId().equals(other.getGoodsId()))
&& (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount()));
&& (this.getDiscount() == null ? other.getDiscount() == null : this.getDiscount().equals(other.getDiscount()))
&& (this.getChannel() == null ? other.getChannel() == null : this.getChannel().equals(other.getChannel()));
}
@Override
@ -139,6 +153,7 @@ public class OutRechargePrice implements Serializable {
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getGoodsId() == null) ? 0 : getGoodsId().hashCode());
result = prime * result + ((getDiscount() == null) ? 0 : getDiscount().hashCode());
result = prime * result + ((getChannel() == null) ? 0 : getChannel().hashCode());
return result;
}
@ -155,6 +170,7 @@ public class OutRechargePrice implements Serializable {
sb.append(", createTime=").append(createTime);
sb.append(", goodsId=").append(goodsId);
sb.append(", discount=").append(discount);
sb.append(", channel=").append(channel);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();

@ -545,6 +545,66 @@ public class OutRechargePriceExample {
addCriterion("discount not between", value1, value2, "discount");
return (Criteria) this;
}
public Criteria andChannelIsNull() {
addCriterion("channel is null");
return (Criteria) this;
}
public Criteria andChannelIsNotNull() {
addCriterion("channel is not null");
return (Criteria) this;
}
public Criteria andChannelEqualTo(Long value) {
addCriterion("channel =", value, "channel");
return (Criteria) this;
}
public Criteria andChannelNotEqualTo(Long value) {
addCriterion("channel <>", value, "channel");
return (Criteria) this;
}
public Criteria andChannelGreaterThan(Long value) {
addCriterion("channel >", value, "channel");
return (Criteria) this;
}
public Criteria andChannelGreaterThanOrEqualTo(Long value) {
addCriterion("channel >=", value, "channel");
return (Criteria) this;
}
public Criteria andChannelLessThan(Long value) {
addCriterion("channel <", value, "channel");
return (Criteria) this;
}
public Criteria andChannelLessThanOrEqualTo(Long value) {
addCriterion("channel <=", value, "channel");
return (Criteria) this;
}
public Criteria andChannelIn(List<Long> values) {
addCriterion("channel in", values, "channel");
return (Criteria) this;
}
public Criteria andChannelNotIn(List<Long> values) {
addCriterion("channel not in", values, "channel");
return (Criteria) this;
}
public Criteria andChannelBetween(Long value1, Long value2) {
addCriterion("channel between", value1, value2, "channel");
return (Criteria) this;
}
public Criteria andChannelNotBetween(Long value1, Long value2) {
addCriterion("channel not between", value1, value2, "channel");
return (Criteria) this;
}
}
/**

@ -1,11 +1,28 @@
package com.hai.service.pay.impl;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.WxUtils;
import com.hai.config.CommonSysConst;
import com.hai.config.TelConfig;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.*;
import com.hai.model.ResultProfitSharing;
import com.hai.service.*;
import com.hai.service.pay.PayService;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@ -13,7 +30,10 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.*;
/**
@ -29,6 +49,16 @@ public class RechargeOrderServiceImpl implements PayService {
@Resource
private OutRechargeOrderService outRechargeOrderService;
@Resource OutRechargePriceService outRechargePriceService;
@Resource
private HighProfitSharingRecordService highProfitSharingRecordService;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper;
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public void paySuccess(Map<String, String> map, String payType) throws Exception {
@ -48,7 +78,140 @@ public class RechargeOrderServiceImpl implements PayService {
order.setPayTime(new Date()); // 支付时间
order.setStatus(2); // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款
outRechargeOrderService.updateOrder(order);
OutRechargePrice outRechargePrice = outRechargePriceService.findById(order.getObjectId());
Map<String, Object> mapOrder = new HashMap<>();
mapOrder.put("cardPhone", order.getRechargeContent());
mapOrder.put("channel", outRechargePrice.getChannel());
mapOrder.put("goodsId", outRechargePrice.getGoodsId());
mapOrder.put("orderAmount", order.getOrderPrice());
mapOrder.put("orderNumber", order.getOrderNo());
mapOrder.put("callbackUrl", CommonSysConst.getSysConfig().getCzOrderNotify());
mapOrder.put("orderTime", order.getCreateTimed());
mapOrder.put("paymentAmount", order.getPayPrice());
JSONObject data = TelConfig.order(mapOrder);
// 推送订单记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
highGasOrderPush.setCreateTime(new Date());
highGasOrderPush.setCode(data.getString("code"));
highGasOrderPush.setRequestContent(JSONObject.toJSONString(mapOrder));
highGasOrderPush.setReturnContent(data.toJSONString());
highGasOrderPushMapper.insert(highGasOrderPush);
}
new Thread(() -> {
try {
Thread.sleep(60*1000);
BigDecimal rake = new BigDecimal("0.01");
// 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN);
BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee);
// 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN);
this.wxProfitsharing(order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
}
public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) {
try {
Map<String,String> param = new LinkedHashMap<>();
param.put("appid", "wx637bd6f7314daa46");
param.put("mch_id", "1289663601");
param.put("sub_mch_id" , "1607303848"); // 九龙坡区烨歌百货经营部
param.put("transaction_id" , transaction_id);
param.put("out_order_no" , out_order_no);
param.put("nonce_str" , WxUtils.makeNonStr());
// 分账金额
BigDecimal porofitSharingAmount = amount;
List<Map<String,Object>> receiversList = new ArrayList<>();
Map<String,Object> receiversMap = new LinkedHashMap<>();
receiversMap.put("type", "MERCHANT_ID");
receiversMap.put("account", "1611202250");
receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue());
receiversMap.put("description", "分给商户【重庆众卡汇电子商务有限公司】");
receiversList.add(receiversMap);
param.put("receivers" , JSONObject.toJSONString(receiversList));
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256);
param.put("sign" , signStr);
String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param));
// 请求分账返回的结果
ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class);
HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord();
sharingRecord.setOutOrderNo(resultProfitSharing.getOut_order_no());
sharingRecord.setTransactionId(resultProfitSharing.getTransaction_id());
sharingRecord.setOrderId(resultProfitSharing.getOrder_id());
sharingRecord.setStatus(resultProfitSharing.getResult_code());
sharingRecord.setPrice(amount);
sharingRecord.setCreateTime(new Date());
sharingRecord.setContent(resultXmL);
highProfitSharingRecordService.insert(sharingRecord);
} catch (Exception e) {
log.error("CmsContentController --> getCorporateAdvertising() error!", e);
}
}
public CloseableHttpClient readCertificate(String mchId) throws Exception{
/**
* 注意PKCS12证书 是从微信商户平台-账户设置- API安全 中下载的
*/
KeyStore keyStore = KeyStore.getInstance("PKCS12");
//P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径
FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12");
// FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12");
try {
keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID
} finally {
instream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, "1289663601".toCharArray()).build();//这里也是写密码的
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
// Allow TLSv1 protocol only
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
public String doRefundRequest(String mchId, String url, String data) throws Exception {
//小程序退款需要调用双向证书的认证
CloseableHttpClient httpClient = readCertificate(mchId);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息
httpost.addHeader("Connection", "keep-alive");
httpost.addHeader("Accept", "*/*");
httpost.addHeader("Content-Type", "text/xml");
httpost.addHeader("Host", "api.mch.weixin.qq.com");
httpost.addHeader("X-Requested-With", "XMLHttpRequest");
httpost.addHeader("Cache-Control", "max-age=0");
httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = httpClient.execute(httpost);
try {
HttpEntity entity = response.getEntity();
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
return jsonStr;
} finally {
response.close();
}
} catch (Exception e){
throw new RuntimeException(e);
} finally {
httpClient.close();
}
}

@ -16,3 +16,4 @@ telApiKey=2d01f6b520254b1a80f6b167832cea18
telApiSecret=d11ee9b41e014a039f030e53ae6f5295
telMemberId=d13091df65d64aafbf0f35d2093157b7
telUrl=http://cz.jjcxy.com:80/api/2d01f6b520254b1a80f6b167832cea18
czOrderNotify=https://cz.cqzhongkahui.com/crest/czOrder/orderRefundNotify

Loading…
Cancel
Save