mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-05 13:17:46 +08:00
果断去掉旧有接口代码
This commit is contained in:
parent
8619430ae5
commit
435eb1250a
@ -19,37 +19,6 @@ import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
|
||||
*/
|
||||
public interface WxMpPayService {
|
||||
|
||||
/**
|
||||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
|
||||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
||||
*
|
||||
* @param openId 支付人openId
|
||||
* @param outTradeNo 商户端对应订单号
|
||||
* @param amt 金额(单位元)
|
||||
* @param body 商品描述
|
||||
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
|
||||
* @param ip 发起支付的客户端IP
|
||||
* @param notifyUrl 通知地址
|
||||
* @throws WxErrorException
|
||||
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPrepayId(Map<String, String>) instead
|
||||
*/
|
||||
@Deprecated
|
||||
WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt,
|
||||
String body, String tradeType, String ip, String notifyUrl)
|
||||
throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
|
||||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
||||
*
|
||||
* @param parameters All required/optional parameters for weixin payment
|
||||
* @throws WxErrorException
|
||||
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.unifiedOrder(WxUnifiedOrderRequest) instead
|
||||
*/
|
||||
@Deprecated
|
||||
WxMpPrepayIdResult getPrepayId(Map<String, String> parameters)
|
||||
throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
|
||||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
||||
@ -60,16 +29,6 @@ public interface WxMpPayService {
|
||||
WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
|
||||
throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||
*
|
||||
* @param parameters the required or optional parameters
|
||||
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, String> getPayInfo(Map<String, String> parameters) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||
@ -77,37 +36,6 @@ public interface WxMpPayService {
|
||||
*/
|
||||
Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||
* tradeType 交易类型 NATIVE (其他交易类型JSAPI,APP,WAP)
|
||||
*
|
||||
* @param productId 商户商品ID
|
||||
* @param outTradeNo 商户端对应订单号
|
||||
* @param amt 金额(单位元)
|
||||
* @param body 商品描述
|
||||
* @param ip 发起支付的客户端IP
|
||||
* @param notifyUrl 通知地址
|
||||
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, String> getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 该接口调用“统一下单”接口,并拼装JSAPI发起支付请求需要的参数
|
||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||
* tradeType 交易类型 JSAPI(其他交易类型NATIVE,APP,WAP)
|
||||
*
|
||||
* @param openId 支付人openId
|
||||
* @param outTradeNo 商户端对应订单号
|
||||
* @param amt 金额(单位元)
|
||||
* @param body 商品描述
|
||||
* @param ip 发起支付的客户端IP
|
||||
* @param notifyUrl 通知地址
|
||||
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
|
||||
@ -148,30 +76,6 @@ public interface WxMpPayService {
|
||||
*/
|
||||
boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm, String signature);
|
||||
|
||||
/**
|
||||
* 发送普通微信红包给个人用户
|
||||
* <pre>
|
||||
* 需要传入的必填参数如下:
|
||||
* mch_billno//商户订单号
|
||||
* send_name//商户名称
|
||||
* re_openid//用户openid
|
||||
* total_amount//红包总额
|
||||
* total_num//红包发放总人数
|
||||
* wishing//红包祝福语
|
||||
* client_ip//服务器Ip地址
|
||||
* act_name//活动名称
|
||||
* remark //备注
|
||||
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
|
||||
* 使用现金红包功能需要在xml配置文件中额外设置:
|
||||
* </pre>
|
||||
* <partnerId></partnerId>微信商户平台ID
|
||||
* <partnerKey></partnerKey>商户平台设置的API密钥
|
||||
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.sendRedpack(WxSendRedpackRequest) instead
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 发送微信红包给个人用户
|
||||
* <pre>
|
||||
|
@ -44,173 +44,12 @@ public class WxMpPayServiceImpl implements WxMpPayService {
|
||||
private static final List<String> TRADE_TYPES = Lists.newArrayList("JSAPI",
|
||||
"NATIVE", "APP");
|
||||
private final Logger log = LoggerFactory.getLogger(WxMpPayServiceImpl.class);
|
||||
private final String[] REQUIRED_ORDER_PARAMETERS = new String[] { "appid",
|
||||
"mch_id", "body", "out_trade_no", "total_fee", "spbill_create_ip",
|
||||
"notify_url", "trade_type" };
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpPayServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo,
|
||||
double amt, String body, String tradeType, String ip,
|
||||
String callbackUrl) throws WxErrorException {
|
||||
Map<String, String> packageParams = new HashMap<>();
|
||||
packageParams.put("appid",
|
||||
this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||
packageParams.put("mch_id",
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerId());
|
||||
packageParams.put("body", body);
|
||||
packageParams.put("out_trade_no", outTradeNo);
|
||||
packageParams.put("total_fee", (int) (amt * 100) + "");
|
||||
packageParams.put("spbill_create_ip", ip);
|
||||
packageParams.put("notify_url", callbackUrl);
|
||||
packageParams.put("trade_type", tradeType);
|
||||
packageParams.put("openid", openId);
|
||||
|
||||
return getPrepayId(packageParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxMpPrepayIdResult getPrepayId(final Map<String, String> parameters)
|
||||
throws WxErrorException {
|
||||
final SortedMap<String, String> packageParams = new TreeMap<>(parameters);
|
||||
packageParams.put("appid",
|
||||
this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||
packageParams.put("mch_id",
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerId());
|
||||
packageParams.put("nonce_str", System.currentTimeMillis() + "");
|
||||
checkParameters(packageParams);
|
||||
|
||||
String sign = this.createSign(packageParams,
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
|
||||
packageParams.put("sign", sign);
|
||||
|
||||
StringBuilder request = new StringBuilder("<xml>");
|
||||
for (Map.Entry<String, String> para : packageParams.entrySet()) {
|
||||
request.append(String.format("<%s>%s</%s>", para.getKey(),
|
||||
para.getValue(), para.getKey()));
|
||||
}
|
||||
|
||||
request.append("</xml>");
|
||||
|
||||
String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
||||
String responseContent = this.wxMpService.post(url, request.toString());
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.alias("xml", WxMpPrepayIdResult.class);
|
||||
return (WxMpPrepayIdResult) xstream.fromXML(responseContent);
|
||||
}
|
||||
|
||||
private void checkParameters(Map<String, String> parameters) {
|
||||
for (String para : this.REQUIRED_ORDER_PARAMETERS) {
|
||||
if (!parameters.containsKey(para)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Reqiured argument '" + para + "' is missing.");
|
||||
}
|
||||
}
|
||||
|
||||
if ("JSAPI".equals(parameters.get("trade_type"))
|
||||
&& !parameters.containsKey("openid")) {
|
||||
throw new IllegalArgumentException(
|
||||
"Reqiured argument 'openid' is missing when trade_type is 'JSAPI'.");
|
||||
}
|
||||
|
||||
if ("NATIVE".equals(parameters.get("trade_type"))
|
||||
&& !parameters.containsKey("product_id")) {
|
||||
throw new IllegalArgumentException(
|
||||
"Reqiured argument 'product_id' is missing when trade_type is 'NATIVE'.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, String> getJsapiPayInfo(String openId, String outTradeNo,
|
||||
double amt, String body, String ip, String callbackUrl)
|
||||
throws WxErrorException {
|
||||
Map<String, String> packageParams = new HashMap<>();
|
||||
packageParams.put("appid",
|
||||
this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||
packageParams.put("mch_id",
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerId());
|
||||
packageParams.put("body", body);
|
||||
packageParams.put("out_trade_no", outTradeNo);
|
||||
packageParams.put("total_fee", (int) (amt * 100) + "");
|
||||
packageParams.put("spbill_create_ip", ip);
|
||||
packageParams.put("notify_url", callbackUrl);
|
||||
packageParams.put("trade_type", "JSAPI");
|
||||
packageParams.put("openid", openId);
|
||||
|
||||
return getPayInfo(packageParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, String> getNativePayInfo(String productId,
|
||||
String outTradeNo, double amt, String body, String ip, String callbackUrl)
|
||||
throws WxErrorException {
|
||||
Map<String, String> packageParams = new HashMap<>();
|
||||
packageParams.put("appid",
|
||||
this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||
packageParams.put("mch_id",
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerId());
|
||||
packageParams.put("body", body);
|
||||
packageParams.put("out_trade_no", outTradeNo);
|
||||
packageParams.put("total_fee", (int) (amt * 100) + "");
|
||||
packageParams.put("spbill_create_ip", ip);
|
||||
packageParams.put("notify_url", callbackUrl);
|
||||
packageParams.put("trade_type", "NATIVE");
|
||||
packageParams.put("product_id", productId);
|
||||
|
||||
return getPayInfo(packageParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<String, String> getPayInfo(Map<String, String> parameters)
|
||||
throws WxErrorException {
|
||||
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
|
||||
|
||||
if (!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getReturn_code())
|
||||
|| !"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getResult_code())) {
|
||||
WxError error = new WxError();
|
||||
error.setErrorCode(-1);
|
||||
error.setErrorMsg("return_code:" + wxMpPrepayIdResult.getReturn_code()
|
||||
+ ";return_msg:" + wxMpPrepayIdResult.getReturn_msg()
|
||||
+ ";result_code:" + wxMpPrepayIdResult.getResult_code() + ";err_code"
|
||||
+ wxMpPrepayIdResult.getErr_code() + ";err_code_des"
|
||||
+ wxMpPrepayIdResult.getErr_code_des());
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
|
||||
String prepayId = wxMpPrepayIdResult.getPrepay_id();
|
||||
if (prepayId == null || prepayId.equals("")) {
|
||||
throw new RuntimeException(
|
||||
String.format("Failed to get prepay id due to error code '%s'(%s).",
|
||||
wxMpPrepayIdResult.getErr_code(),
|
||||
wxMpPrepayIdResult.getErr_code_des()));
|
||||
}
|
||||
|
||||
Map<String, String> payInfo = new HashMap<>();
|
||||
payInfo.put("appId", this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||
payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
|
||||
payInfo.put("nonceStr", System.currentTimeMillis() + "");
|
||||
payInfo.put("package", "prepay_id=" + prepayId);
|
||||
payInfo.put("signType", "MD5");
|
||||
if ("NATIVE".equals(parameters.get("trade_type"))) {
|
||||
payInfo.put("codeUrl", wxMpPrepayIdResult.getCode_url());
|
||||
}
|
||||
|
||||
String finalSign = this.createSign(payInfo,
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
|
||||
payInfo.put("paySign", finalSign);
|
||||
return payInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpPayResult getJSSDKPayResult(String transactionId,
|
||||
String outTradeNo) throws WxErrorException {
|
||||
@ -313,37 +152,6 @@ public class WxMpPayServiceImpl implements WxMpPayService {
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public WxRedpackResult sendRedpack(Map<String, String> parameters)
|
||||
throws WxErrorException {
|
||||
SortedMap<String, String> packageParams = new TreeMap<>(parameters);
|
||||
packageParams.put("wxappid",
|
||||
this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||
packageParams.put("mch_id",
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerId());
|
||||
packageParams.put("nonce_str", System.currentTimeMillis() + "");
|
||||
|
||||
String sign = this.createSign(packageParams,
|
||||
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
|
||||
packageParams.put("sign", sign);
|
||||
|
||||
StringBuilder request = new StringBuilder("<xml>");
|
||||
for (Map.Entry<String, String> para : packageParams.entrySet()) {
|
||||
request.append(String.format("<%s>%s</%s>", para.getKey(),
|
||||
para.getValue(), para.getKey()));
|
||||
}
|
||||
|
||||
request.append("</xml>");
|
||||
|
||||
String url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
|
||||
|
||||
String responseContent = this.wxMpService.post(url, request.toString());
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.processAnnotations(WxRedpackResult.class);
|
||||
return (WxRedpackResult) xstream.fromXML(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxRedpackResult sendRedpack(WxSendRedpackRequest request)
|
||||
throws WxErrorException {
|
||||
|
@ -85,7 +85,7 @@ public class WxMpPayServiceImplTest {
|
||||
WxUnifiedOrderResult result = this.wxService.getPayService()
|
||||
.unifiedOrder(WxUnifiedOrderRequest.builder().body("1111111")
|
||||
.totalFee(1).spbillCreateIp("111111").notifyURL("111111")
|
||||
.tradeType("JSAPI1").openid("122").outTradeNo("111111").build());
|
||||
.tradeType("JSAPI").openid("122").outTradeNo("111111").build());
|
||||
System.err.println(result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user