提交代码

dev-discount
= 4 years ago
parent f67c6dd39d
commit 29d111246f
  1. 87
      hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java
  2. 4
      hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java
  3. 4
      hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java

@ -15,10 +15,7 @@ import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.*;
import com.hai.entity.HighChildOrder;
import com.hai.entity.HighCoupon;
import com.hai.entity.HighOrder;
import com.hai.entity.OutRechargeOrder;
import com.hai.entity.*;
import com.hai.model.HighUserModel;
import com.hai.model.OrderRefundModel;
import com.hai.model.ResponseData;
@ -45,10 +42,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
@Controller
@ -369,4 +363,81 @@ public class OutRechargeOrderController {
httpClient.close();
}
}
@RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "订单退款")
public ResponseData 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" , "1289663601");
param.put("sub_mch_id" , "1609882817"); // 个体黎杨珍
param.put("transaction_id" , "4200001165202106115006937316");
param.put("out_order_no" , String.valueOf(new Date().getTime()));
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", "1603942866");// 嗨加油
receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue());
receiversMap.put("description", "分给商户1289663601");
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.doRefundRequest2(param.get("mch_id"),null, WxUtils.mapToXml(param));
// 请求分账返回的结果
ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class);
return ResponseMsgUtil.success(resultProfitSharing);
/* 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);
return ResponseMsgUtil.success(e);
}
}
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"); // 设置响应头信息
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();
}
}
}

@ -118,9 +118,9 @@ public class WechatPayController {
try {
WxSharingReceiversVO receiversVO = new WxSharingReceiversVO();
receiversVO.setAccount("1603942866");
receiversVO.setAccount("1604968055");
receiversVO.setType("MERCHANT_ID");
receiversVO.setName("重庆惠昕石化有限责任公司");
receiversVO.setName("嗨加油");
receiversVO.setRelation_type("SERVICE_PROVIDER");
Map<String , String> map = new HashMap<>();

@ -194,8 +194,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