'提交代码'

dev-discount
= 3 years ago
parent 7482b3666a
commit 2150f17aa7
  1. 28
      hai-cweb/src/main/java/com/cweb/config/SysConfig.java
  2. 192
      hai-cweb/src/main/java/com/cweb/config/TuanYouConfig.java
  3. 25
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  4. 93
      hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java
  5. 4
      hai-cweb/src/main/resources/dev/config.properties
  6. 8
      hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java

@ -17,6 +17,10 @@ public class SysConfig {
private String wxH5AppId;
private String wxH5AppSecret;
private String tuanYouUrl;
private String tuanYouAppKey;
private String tuanYouAppSecret;
private String wxApiKey;
private String wxMchId;
private String wxMchAppId;
@ -26,6 +30,14 @@ public class SysConfig {
private String couponCodePath;
private String notifyUrl;
public String getTuanYouUrl() {
return tuanYouUrl;
}
public void setTuanYouUrl(String tuanYouUrl) {
this.tuanYouUrl = tuanYouUrl;
}
public String getFileUrl() {
return fileUrl;
}
@ -129,4 +141,20 @@ public class SysConfig {
public void setWxH5AppSecret(String wxH5AppSecret) {
this.wxH5AppSecret = wxH5AppSecret;
}
public String getTuanYouAppKey() {
return tuanYouAppKey;
}
public void setTuanYouAppKey(String tuanYouAppKey) {
this.tuanYouAppKey = tuanYouAppKey;
}
public String getTuanYouAppSecret() {
return tuanYouAppSecret;
}
public void setTuanYouAppSecret(String tuanYouAppSecret) {
this.tuanYouAppSecret = tuanYouAppSecret;
}
}

@ -0,0 +1,192 @@
package com.cweb.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.MD5Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
/**
* 团油请求
*/
public class TuanYouConfig {
private static final Logger log = LoggerFactory.getLogger(TuanYouConfig.class);
/**
* 分页获取(全量)油站信息
* @param pageIndex 页数
* @param pageSize 单页数据量最大 3000
* @return 请求结果
* @throws Exception
*/
public static JSONObject queryGasInfoListByPage(Integer pageIndex,Integer pageSize) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("pageIndex", pageIndex);
paramMap.put("pageSize", pageSize);
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/queryGasInfoListByPage", JSON.toJSONString(paramMap));
}
/**
* 根据油站 id 拉取最新的油站数据
* @param gasId 油站 ID
* @return 请求结果
* @throws Exception
*/
public static JSONObject queryGasInfoByGasId(String gasId) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("gasId", gasId);
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/queryGasInfoByGasId", JSON.toJSONString(paramMap));
}
/**
* 查询油站某油号实时价格
* @param gasId 加油站id
* @param oilNo 油号id
* @return 请求结果
* @throws Exception
*/
public static JSONObject queryCompanyPriceDetail(String gasId,String oilNo) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("gasId", gasId);
paramMap.put("oilNo", oilNo);
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/queryCompanyPriceDetail", JSON.toJSONString(paramMap));
}
/**
* 推送订单
* @param map
* @return 请求结果
* @throws Exception
*/
public static JSONObject refuelingOrderPush(Map<String,Object> map) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
for (Map.Entry<String, Object> entry : map.entrySet()) {
paramMap.put(entry.getKey(), entry.getValue().toString());
}
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/refuelingOrderPush", JSON.toJSONString(paramMap));
}
/**
* 订单退款
* @param driverPhone 司机手机号
* @param thirdSerialNo 三方订单号
* @param refundReason 退款原因
* @return 请求结果
* @throws Exception
*/
public static JSONObject refuelingOrderRefund(String driverPhone,String thirdSerialNo,String refundReason) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("driverPhone", driverPhone);
paramMap.put("thirdSerialNo", thirdSerialNo);
paramMap.put("refundReason", refundReason);
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/refuelingOrderRefund", JSON.toJSONString(paramMap));
}
/**
* 订单结果查询
* @param thirdSerialNo 三方订单号
* @return 请求结果
* @throws Exception
*/
public static JSONObject queryThirdOrderDretail(String thirdSerialNo) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("thirdSerialNo", thirdSerialNo);
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/queryThirdOrderDretail", JSON.toJSONString(paramMap));
}
/**
* 订单列表查询
* @param companyCode 公司 code AppKey
* @param startTime 查询开始时间 2018-11-30 12:28:55
* @param endTime 查询结束时间 2018-11-30 16:28
* @param page 页码缺省默认 1
* @param rows 每页记录行数缺省默认 20最大值 200
* @param orderPayFlag 订单状态 未支付:1, 已支付:3, 退款中:5, 已退款:6,退款失败:7;
* @return
* @throws Exception
*/
public static JSONObject queryOrderInfoList(String companyCode,String startTime,String endTime,Integer page,Integer rows,Integer orderPayFlag) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("companyCode", companyCode);
paramMap.put("startTime", startTime);
paramMap.put("endTime", endTime);
if (page != null) {
paramMap.put("page", page);
}
if (rows != null) {
paramMap.put("rows", rows);
}
if (orderPayFlag != null) {
paramMap.put("orderPayFlag", orderPayFlag);
}
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/queryOrderInfoList", JSON.toJSONString(paramMap));
}
/**
* 上汽油站下单结果查询
* @param thirdSerialNo 三方订单号
* @return
* @throws Exception
*/
public static JSONObject loopShangQiOrder(String thirdSerialNo) throws Exception {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("app_key", SysConst.getSysConfig().getTuanYouAppKey());
paramMap.put("timestamp", new Date().getTime());
paramMap.put("thirdSerialNo", thirdSerialNo);
paramMap.put("sign", MD5Util.encode(generateTuanYouSignature(paramMap,SysConst.getSysConfig().getTuanYouAppSecret()).getBytes()).toLowerCase());
return HttpsUtils.doPost(SysConst.getSysConfig().getTuanYouUrl()+"/services/vp/openapi/loopShangQiOrder", JSON.toJSONString(paramMap));
}
/**
* 生成签名
* @param data 数据
* @param key 秘钥app_secret
* @return 加密结果
*/
public static String generateTuanYouSignature(final Map<String, Object> data, String key){
Set<String> keySet = data.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]);
Arrays.sort(keyArray);
StringBuilder sb = new StringBuilder();
sb.append(key);
for (String k : keyArray) {
if (k.equals(WXPayConstants.FIELD_SIGN)) {
continue;
}
if (data.get(k) != null) // 参数值为空,则不参与签名
sb.append(k).append(data.get(k));
}
sb.append(key);
return sb.toString();
}
}

@ -1,6 +1,9 @@
package com.cweb.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cweb.config.TuanYouConfig;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode;
@ -49,21 +52,15 @@ public class HighTestController {
public ResponseData getOrderById() {
try {
Map<String,Object> map = new HashMap<>();
map.put("app_key", "208241666939552");
//map.put("app_secret", "adecc3cff077834cb8632c8ab3bec0e6");
map.put("timestamp", new Date().getTime());
map.put("pageIndex", 1);
map.put("pageSize", 10);
String signStr = "adecc3cff077834cb8632c8ab3bec0e6" + WxUtils.generateSignature(map,"adecc3cff077834cb8632c8ab3bec0e6") + "adecc3cff077834cb8632c8ab3bec0e6";
System.out.println("加密前:" + signStr);
String sign = MD5Util.encode(signStr.getBytes()).toLowerCase();
System.out.println("加密后:" + sign);
map.put("sign", sign);
return ResponseMsgUtil.success(HttpsUtils.doPost("https://test02-motorcade-hcs.czb365.com/services/vp/openapi/queryGasInfoListByPage", JSON.toJSONString(map)));
JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(1, 10);
JSONObject resultObject = jsonObject.getObject("result", JSONObject.class);
JSONArray jsonArray = resultObject.getJSONArray("gasInfoList");
for (Object gasObject : jsonArray) {
JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject));
System.out.println(object.getString("gasName"));
}
return ResponseMsgUtil.success(jsonArray);
} catch (Exception e) {
log.error("HighOrderController --> getOrderById() error!", e);
return ResponseMsgUtil.exception(e);

@ -329,37 +329,6 @@ public class OutRechargeOrderController {
}
public String doRefundRequest(String mchId, String url, String data) throws Exception {
//小程序退款需要调用双向证书的认证
CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息
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();
}
}
@RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "分账")
@ -396,7 +365,7 @@ public class OutRechargeOrderController {
param.put("receivers" , JSONObject.toJSONString(receiversList));
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256);
param.put("sign" , signStr);
String resultXmL = this.doRefundRequest2(param.get("mch_id"),null, WxUtils.mapToXml(param));
String resultXmL = this.doRefundRequest2(param.get("mch_id"),"https://api.mch.weixin.qq.com/secapi/pay/profitsharing", WxUtils.mapToXml(param));
// 请求分账返回的结果
ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class);
return ResponseMsgUtil.success(resultProfitSharing);
@ -416,6 +385,33 @@ public class OutRechargeOrderController {
}
}
@RequestMapping(value = "/wxEndProfitsharing", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "完结分账")
public ResponseData wxEndProfitsharing(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" , "1609882817"); // 个体户黎杨珍
param.put("nonce_str" , WxUtils.makeNonStr());
param.put("transaction_id" , "4200001148202106176001512773");
param.put("out_order_no" , "HF2021061710360517203");
param.put("description" , "系统自动完结分账");
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256);
param.put("sign" , signStr);
String resultXmL = this.doRefundRequest2(param.get("mch_id"),"https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish", WxUtils.mapToXml(param));
// 请求分账返回的结果
ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class);
return ResponseMsgUtil.success(resultXmL);
} catch (Exception e) {
log.error("CmsContentController --> getCorporateAdvertising() error!", e);
return ResponseMsgUtil.success(e);
}
}
@RequestMapping(value = "/wxSelectProfitsharing", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询剩余分账金额")
@ -437,12 +433,43 @@ public class OutRechargeOrderController {
return ResponseMsgUtil.success(e);
}
}
public String doRefundRequest(String mchId, String url, String data) throws Exception {
//小程序退款需要调用双向证书的认证
CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息
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();
}
}
public String doRefundRequest2(String mchId, String url, String data) throws Exception {
//小程序退款需要调用双向证书的认证
CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/profitsharing"); // 设置响应头信息
HttpPost httpost = new HttpPost(url); // 设置响应头信息
httpost.addHeader("Connection", "keep-alive");
httpost.addHeader("Accept", "*/*");
httpost.addHeader("Content-Type", "text/xml");

@ -5,6 +5,10 @@ wxAppSecret=d8d6dcaef77d3b659258a01b5ddba5df
wxH5AppId=wxa075e8509802f826
wxH5AppSecret=0e606fc1378d35e359fcf3f15570b2c5
tuanYouUrl=https://test02-motorcade-hcs.czb365.com
tuanYouAppKey=208241666939552
tuanYouAppSecret=adecc3cff077834cb8632c8ab3bec0e6
wxApiKey=Skufk5oi85wDFGl888i6wsRSTkdd5df5
wxMchAppId=wx637bd6f7314daa46
wxMchId=1289663601

@ -142,6 +142,8 @@ public class GoodsOrderServiceImpl implements PayService {
BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN);
this.wxProfitsharing(order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount);
} catch (InterruptedException e) {
e.printStackTrace();
}
@ -169,7 +171,7 @@ public class GoodsOrderServiceImpl implements PayService {
receiversMap.put("type", "MERCHANT_ID");
receiversMap.put("account", "1603942866");
receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue());
receiversMap.put("description", "分给商户【重庆慧听石化有限责任公司】");
receiversMap.put("description", "分给商户【惠昕石化】");
receiversList.add(receiversMap);
param.put("receivers" , JSONObject.toJSONString(receiversList));
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256);
@ -201,8 +203,8 @@ public class GoodsOrderServiceImpl implements PayService {
*/
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");
// 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 {

Loading…
Cancel
Save