调用发货录入管理相关
This commit is contained in:
@@ -26,6 +26,8 @@ public class OrderDto implements Dto {
|
|||||||
private int timeRemarks;
|
private int timeRemarks;
|
||||||
@ApiModelProperty("回调地址")
|
@ApiModelProperty("回调地址")
|
||||||
private String returnUrl;
|
private String returnUrl;
|
||||||
|
@ApiModelProperty("返回预下单时间地址")
|
||||||
|
private String payUrl;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ public class PayOrder extends BaseEntity {
|
|||||||
|
|
||||||
private String returnUrl;
|
private String returnUrl;
|
||||||
|
|
||||||
|
@ApiModelProperty("返回预下单时间地址")
|
||||||
|
private String payUrl;
|
||||||
|
|
||||||
|
|
||||||
public String getTime() {
|
public String getTime() {
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ public class WxPayVo {
|
|||||||
private String appId;
|
private String appId;
|
||||||
private String mchId;
|
private String mchId;
|
||||||
private String secret;
|
private String secret;
|
||||||
|
private String appSecret;
|
||||||
|
|
||||||
public WxPayVo(int source) {
|
public WxPayVo(int source) {
|
||||||
if (source == 0) {//云菜窖
|
if (source == 0) {//云菜窖
|
||||||
appId = "wx4724e3a3c27f36b5";
|
appId = "wx4724e3a3c27f36b5";
|
||||||
mchId = "1664882765";
|
mchId = "1664882765";
|
||||||
secret = "yxtcxjshbyxgs1234567898765432101";
|
secret = "yxtcxjshbyxgs1234567898765432101";
|
||||||
|
appSecret = "971fd3b8aa7b08ce3e8a5f3e502b1a8d";
|
||||||
|
|
||||||
} else if (source == 1) {
|
} else if (source == 1) {
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.yxt.pay.biz.order;
|
|||||||
import com.yxt.common.core.result.ResultBean;
|
import com.yxt.common.core.result.ResultBean;
|
||||||
import com.yxt.pay.api.order.OrderDto;
|
import com.yxt.pay.api.order.OrderDto;
|
||||||
import com.yxt.pay.api.order.OrderQuery;
|
import com.yxt.pay.api.order.OrderQuery;
|
||||||
|
import com.yxt.pay.api.order.PayOrder;
|
||||||
import com.yxt.pay.api.order.PayOrderVo;
|
import com.yxt.pay.api.order.PayOrderVo;
|
||||||
import com.yxt.pay.utils.ApiBaseAction;
|
import com.yxt.pay.utils.ApiBaseAction;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -30,6 +31,8 @@ public class OrderRest extends ApiBaseAction {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrderService orderService;
|
private OrderService orderService;
|
||||||
|
@Autowired
|
||||||
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
@PostMapping("/createOrder")
|
@PostMapping("/createOrder")
|
||||||
ResultBean<PayOrderVo> createOrder(@RequestBody OrderDto dto) {
|
ResultBean<PayOrderVo> createOrder(@RequestBody OrderDto dto) {
|
||||||
@@ -46,7 +49,7 @@ public class OrderRest extends ApiBaseAction {
|
|||||||
return orderService.wxPayNotify(request, response);
|
return orderService.wxPayNotify(request, response);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@PostMapping( "/wxPayNotify")
|
@PostMapping("/wxPayNotify")
|
||||||
public String payNotify(HttpServletRequest request) {
|
public String payNotify(HttpServletRequest request) {
|
||||||
return orderService.payNotify(request);
|
return orderService.payNotify(request);
|
||||||
}
|
}
|
||||||
@@ -60,4 +63,12 @@ public class OrderRest extends ApiBaseAction {
|
|||||||
ResultBean orderQuery(OrderQuery query) {
|
ResultBean orderQuery(OrderQuery query) {
|
||||||
return orderService.orderQuery(query);
|
return orderService.orderQuery(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/sendGoods")
|
||||||
|
ResultBean sendGoods(@RequestParam("out_trade_no") String out_trade_no) {
|
||||||
|
ResultBean rb = ResultBean.fireFail();
|
||||||
|
PayOrder payOrder = orderMapper.selectBySn(out_trade_no);
|
||||||
|
String errCode = orderService.toSendGoods(payOrder);
|
||||||
|
return rb.success().setData(errCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.yxt.pay.biz.order;
|
package com.yxt.pay.biz.order;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.sun.org.apache.bcel.internal.generic.RETURN;
|
import com.sun.org.apache.bcel.internal.generic.RETURN;
|
||||||
import com.yxt.common.base.service.MybatisBaseService;
|
import com.yxt.common.base.service.MybatisBaseService;
|
||||||
import com.yxt.common.core.result.ResultBean;
|
import com.yxt.common.core.result.ResultBean;
|
||||||
@@ -13,7 +16,7 @@ import com.yxt.pay.utils.wx.SignType;
|
|||||||
import com.yxt.pay.utils.wx.WxPayKit;
|
import com.yxt.pay.utils.wx.WxPayKit;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
@@ -23,6 +26,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -88,6 +93,7 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
return rb.setMsg("订单不是未支付,不能重复支付");
|
return rb.setMsg("订单不是未支付,不能重复支付");
|
||||||
}
|
}
|
||||||
Map<Object, Object> resultObj = new TreeMap();
|
Map<Object, Object> resultObj = new TreeMap();
|
||||||
|
String date = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||||
if (query.getType().equals(PayTypeEnum.WECHAT.getCode())) {//微信
|
if (query.getType().equals(PayTypeEnum.WECHAT.getCode())) {//微信
|
||||||
WxPayVo wxPayVo = new WxPayVo(payOrder.getSource());
|
WxPayVo wxPayVo = new WxPayVo(payOrder.getSource());
|
||||||
String nonceStr = CharUtil.getRandomString(32);
|
String nonceStr = CharUtil.getRandomString(32);
|
||||||
@@ -146,6 +152,10 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
resultObj.put("prepayid", prepay_id);//预支付交易会话ID
|
resultObj.put("prepayid", prepay_id);//预支付交易会话ID
|
||||||
payOrder.setPayType(PayTypeEnum.WECHAT.getCode());
|
payOrder.setPayType(PayTypeEnum.WECHAT.getCode());
|
||||||
baseMapper.updateById(payOrder);
|
baseMapper.updateById(payOrder);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("mainSid", payOrder.getSid());
|
||||||
|
map.put("payTime", date);
|
||||||
|
ResponseEntity<ResultBean> postForEntity = new RestTemplate().postForEntity(payOrder.getPayUrl(), map, ResultBean.class);
|
||||||
return rb.success().setData(resultObj);
|
return rb.success().setData(resultObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +329,8 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
baseMapper.updateById(payOrder);
|
baseMapper.updateById(payOrder);
|
||||||
//调业务的回调地址接口。mainSid传过去。
|
//调业务的回调地址接口。mainSid传过去。
|
||||||
ResponseEntity<ResultBean> postForEntity = new RestTemplate().getForEntity(payOrder.getReturnUrl() + payOrder.getSid(), ResultBean.class);
|
ResponseEntity<ResultBean> postForEntity = new RestTemplate().getForEntity(payOrder.getReturnUrl() + payOrder.getSid(), ResultBean.class);
|
||||||
|
String errCode = toSendGoods(payOrder);
|
||||||
|
log.info("发货通知errcode======" + errCode);
|
||||||
// 发送通知等
|
// 发送通知等
|
||||||
Map<String, String> xml = new HashMap<String, String>(2);
|
Map<String, String> xml = new HashMap<String, String>(2);
|
||||||
xml.put("return_code", "SUCCESS");
|
xml.put("return_code", "SUCCESS");
|
||||||
@@ -331,4 +343,75 @@ public class OrderService extends MybatisBaseService<OrderMapper, PayOrder> {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toSendGoods(PayOrder payOrder) {
|
||||||
|
String accessToken = getAccessToken(payOrder);
|
||||||
|
WxPayVo wxPayVo = new WxPayVo(payOrder.getSource());
|
||||||
|
String url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" + accessToken;
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("mchid", wxPayVo.getMchId());
|
||||||
|
map.put("out_trade_no", payOrder.getOutTradeNo());
|
||||||
|
map.put("order_number_type", 1);
|
||||||
|
|
||||||
|
Map<String, Object> map2 = new HashMap<>();
|
||||||
|
map2.put("openid", payOrder.getOpenId());
|
||||||
|
Map<String, Object> map3 = new HashMap<>();
|
||||||
|
map3.put("item_desc", payOrder.getName());
|
||||||
|
|
||||||
|
JSONObject signObject = new JSONObject();
|
||||||
|
JSONArray objects = new JSONArray();
|
||||||
|
objects.add(map3);
|
||||||
|
|
||||||
|
signObject.put("order_key", map);
|
||||||
|
signObject.put("delivery_mode", 1);
|
||||||
|
//物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式
|
||||||
|
// 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
|
||||||
|
signObject.put("logistics_type", 4);
|
||||||
|
signObject.put("shipping_list", objects);
|
||||||
|
// signObject.put("upload_time", "2023-10-23T0:08:35.120+08:00");
|
||||||
|
signObject.put("upload_time", DateUtil.format(new Date(), "yyyy-MM-dd'T'HH:mm:ssXXX"));
|
||||||
|
signObject.put("payer", map2);
|
||||||
|
System.out.println(signObject);
|
||||||
|
|
||||||
|
HttpEntity<JSONObject> requestEntity = new HttpEntity<JSONObject>(signObject, headers);
|
||||||
|
ResponseEntity<String> responseEntity = new RestTemplate().exchange(url, HttpMethod.POST, requestEntity, String.class);
|
||||||
|
String body = responseEntity.getBody();
|
||||||
|
JSONObject jsonObject = JSONArray.parseObject(body);
|
||||||
|
return jsonObject.getString("errcode");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccessToken(PayOrder payOrder) {
|
||||||
|
WxPayVo wxPayVo = new WxPayVo(payOrder.getSource());
|
||||||
|
log.info("initAccessToken:开始运行...");
|
||||||
|
String accessToken = null;
|
||||||
|
//获取tokcen接口
|
||||||
|
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxPayVo.getAppId() + "&secret=" + wxPayVo.getAppSecret();
|
||||||
|
try {
|
||||||
|
URL urlGet = new URL(url);
|
||||||
|
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
|
||||||
|
http.setRequestMethod("GET"); // 必须是get方式请求
|
||||||
|
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
http.setDoOutput(true);
|
||||||
|
http.setDoInput(true);
|
||||||
|
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
|
||||||
|
System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
|
||||||
|
http.connect();
|
||||||
|
InputStream is = http.getInputStream();
|
||||||
|
int size = is.available();
|
||||||
|
byte[] jsonBytes = new byte[size];
|
||||||
|
is.read(jsonBytes);
|
||||||
|
String message = new String(jsonBytes, "UTF-8");
|
||||||
|
JSONObject demoJson = JSONObject.parseObject(message);
|
||||||
|
accessToken = demoJson.getString("access_token");
|
||||||
|
|
||||||
|
log.info("返回accessToken:" + accessToken);
|
||||||
|
log.info("initAccessToken:运行结束...");
|
||||||
|
is.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user