123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- package com.fdkankan.pay.wx.sdk;
- import javax.net.ssl.HttpsURLConnection;
- import javax.net.ssl.KeyManagerFactory;
- import javax.net.ssl.SSLContext;
- import java.io.*;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.security.KeyStore;
- import java.security.SecureRandom;
- import java.util.HashMap;
- import java.util.Map;
- public class WXPay {
- private WXPayConfig config;
- private WXPayConstants.SignType signType;
- private boolean useSandbox;
- public WXPay(final WXPayConfig config) {
- this(config, WXPayConstants.SignType.MD5, false);
- }
- public WXPay(final WXPayConfig config, final WXPayConstants.SignType signType) {
- this(config, signType, false);
- }
- public WXPay(final WXPayConfig config, final WXPayConstants.SignType signType, final boolean useSandbox) {
- this.config = config;
- this.signType = signType;
- this.useSandbox = useSandbox;
- }
- /**
- * 向 Map 中添加 appid、mch_id、nonce_str、sign_type、sign <br>
- * 该函数适用于商户适用于统一下单等接口,不适用于红包、代金券接口
- *
- * @param reqData
- * @return
- * @throws Exception
- */
- public Map<String, String> fillRequestData(Map<String, String> reqData) throws Exception {
- reqData.put("appid", config.getAppID());
- reqData.put("mch_id", config.getMchID());
- reqData.put("nonce_str", WXPayUtil.generateNonceStr());
- if (WXPayConstants.SignType.MD5.equals(this.signType)) {
- reqData.put("sign_type", WXPayConstants.MD5);
- }
- else if (WXPayConstants.SignType.HMACSHA256.equals(this.signType)) {
- reqData.put("sign_type", WXPayConstants.HMACSHA256);
- }
- reqData.put("sign", WXPayUtil.generateSignature(reqData, config.getKey(), this.signType));
- return reqData;
- }
- /**
- * 判断xml数据的sign是否有效,必须包含sign字段,否则返回false。
- *
- * @param reqData 向wxpay post的请求数据
- * @return 签名是否有效
- * @throws Exception
- */
- public boolean isResponseSignatureValid(Map<String, String> reqData) throws Exception {
- // 返回数据的签名方式和请求中给定的签名方式是一致的
- return WXPayUtil.isSignatureValid(reqData, this.config.getKey(), this.signType);
- }
- /**
- * 判断支付结果通知中的sign是否有效
- *
- * @param reqData 向wxpay post的请求数据
- * @return 签名是否有效
- * @throws Exception
- */
- public boolean isPayResultNotifySignatureValid(Map<String, String> reqData) throws Exception {
- String signTypeInData = reqData.get(WXPayConstants.FIELD_SIGN_TYPE);
- WXPayConstants.SignType signType;
- if (signTypeInData == null) {
- signType = WXPayConstants.SignType.MD5;
- }
- else {
- signTypeInData = signTypeInData.trim();
- if (signTypeInData.length() == 0) {
- signType = WXPayConstants.SignType.MD5;
- }
- else if (WXPayConstants.MD5.equals(signTypeInData)) {
- signType = WXPayConstants.SignType.MD5;
- }
- else if (WXPayConstants.HMACSHA256.equals(signTypeInData)) {
- signType = WXPayConstants.SignType.HMACSHA256;
- }
- else {
- throw new Exception(String.format("Unsupported sign_type: %s", signTypeInData));
- }
- }
- return WXPayUtil.isSignatureValid(reqData, this.config.getKey(), signType);
- }
- /**
- * 不需要证书的请求
- * @param strUrl String
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 超时时间,单位是毫秒
- * @param readTimeoutMs 超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public String requestWithoutCert(String strUrl, Map<String, String> reqData,
- int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String UTF8 = "UTF-8";
- String reqBody = WXPayUtil.mapToXml(reqData);
- URL httpUrl = new URL(strUrl);
- HttpURLConnection httpURLConnection = (HttpURLConnection) httpUrl.openConnection();
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setConnectTimeout(connectTimeoutMs);
- httpURLConnection.setReadTimeout(readTimeoutMs);
- httpURLConnection.connect();
- OutputStream outputStream = httpURLConnection.getOutputStream();
- outputStream.write(reqBody.getBytes(UTF8));
- // if (httpURLConnection.getResponseCode()!= 200) {
- // throw new Exception(String.format("HTTP response code is %d, not 200", httpURLConnection.getResponseCode()));
- // }
- //获取内容
- InputStream inputStream = httpURLConnection.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, UTF8));
- final StringBuffer stringBuffer = new StringBuffer();
- String line = null;
- while ((line = bufferedReader.readLine()) != null) {
- stringBuffer.append(line).append("\n");
- }
- String resp = stringBuffer.toString();
- if (stringBuffer!=null) {
- try {
- bufferedReader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (inputStream!=null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (outputStream!=null) {
- try {
- outputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // if (httpURLConnection!=null) {
- // httpURLConnection.disconnect();
- // }
- return resp;
- }
- /**
- * 需要证书的请求
- * @param strUrl String
- * @param reqData 向wxpay post的请求数据 Map
- * @param connectTimeoutMs 超时时间,单位是毫秒
- * @param readTimeoutMs 超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public String requestWithCert(String strUrl, Map<String, String> reqData,
- int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String UTF8 = "UTF-8";
- String reqBody = WXPayUtil.mapToXml(reqData);
- URL httpUrl = new URL(strUrl);
- char[] password = config.getMchID().toCharArray();
- InputStream certStream = config.getCertStream();
- KeyStore ks = KeyStore.getInstance("PKCS12");
- ks.load(certStream, password);
- // 实例化密钥库 & 初始化密钥工厂
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- kmf.init(ks, password);
- // 创建SSLContext
- SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
- HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
- HttpURLConnection httpURLConnection = (HttpURLConnection) httpUrl.openConnection();
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setConnectTimeout(connectTimeoutMs);
- httpURLConnection.setReadTimeout(readTimeoutMs);
- httpURLConnection.connect();
- OutputStream outputStream = httpURLConnection.getOutputStream();
- outputStream.write(reqBody.getBytes(UTF8));
- // if (httpURLConnection.getResponseCode()!= 200) {
- // throw new Exception(String.format("HTTP response code is %d, not 200", httpURLConnection.getResponseCode()));
- // }
- //获取内容
- InputStream inputStream = httpURLConnection.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, UTF8));
- final StringBuffer stringBuffer = new StringBuffer();
- String line = null;
- while ((line = bufferedReader.readLine()) != null) {
- stringBuffer.append(line);
- }
- String resp = stringBuffer.toString();
- if (stringBuffer!=null) {
- try {
- bufferedReader.close();
- } catch (IOException e) {
- // e.printStackTrace();
- }
- }
- if (inputStream!=null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- // e.printStackTrace();
- }
- }
- if (outputStream!=null) {
- try {
- outputStream.close();
- } catch (IOException e) {
- // e.printStackTrace();
- }
- }
- if (certStream!=null) {
- try {
- certStream.close();
- } catch (IOException e) {
- // e.printStackTrace();
- }
- }
- // if (httpURLConnection!=null) {
- // httpURLConnection.disconnect();
- // }
- return resp;
- }
- /**
- * 处理 HTTPS API返回数据,转换成Map对象。return_code为SUCCESS时,验证签名。
- * @param xmlStr API返回的XML格式数据
- * @return Map类型数据
- * @throws Exception
- */
- public Map<String, String> processResponseXml(String xmlStr) throws Exception {
- String RETURN_CODE = "return_code";
- String return_code;
- Map<String, String> respData = WXPayUtil.xmlToMap(xmlStr);
- if (respData.containsKey(RETURN_CODE)) {
- return_code = respData.get(RETURN_CODE);
- }
- else {
- throw new Exception(String.format("No `return_code` in XML: %s", xmlStr));
- }
- if (return_code.equals(WXPayConstants.FAIL)) {
- return respData;
- }
- else if (return_code.equals(WXPayConstants.SUCCESS)) {
- if (this.isResponseSignatureValid(respData)) {
- return respData;
- }
- else {
- throw new Exception(String.format("Invalid sign value in XML: %s", xmlStr));
- }
- }
- else {
- throw new Exception(String.format("return_code value %s is invalid in XML: %s", return_code, xmlStr));
- }
- }
- /**
- * 作用:提交刷卡支付<br>
- * 场景:刷卡支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> microPay(Map<String, String> reqData) throws Exception {
- return this.microPay(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:提交刷卡支付<br>
- * 场景:刷卡支付
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> microPay(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_MICROPAY_URL;
- }
- else {
- url = WXPayConstants.MICROPAY_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:统一下单<br>
- * 场景:公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> unifiedOrder(Map<String, String> reqData) throws Exception {
- return this.unifiedOrder(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:统一下单<br>
- * 场景:公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> unifiedOrder(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_UNIFIEDORDER_URL;
- }
- else {
- url = WXPayConstants.UNIFIEDORDER_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:查询订单<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> orderQuery(Map<String, String> reqData) throws Exception {
- return this.orderQuery(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:查询订单<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据 int
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> orderQuery(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_ORDERQUERY_URL;
- }
- else {
- url = WXPayConstants.ORDERQUERY_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:撤销订单<br>
- * 场景:刷卡支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> reverse(Map<String, String> reqData) throws Exception {
- return this.reverse(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:撤销订单<br>
- * 场景:刷卡支付<br>
- * 其他:需要证书
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> reverse(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_REVERSE_URL;
- }
- else {
- url = WXPayConstants.REVERSE_URL;
- }
- String respXml = this.requestWithCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:关闭订单<br>
- * 场景:公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> closeOrder(Map<String, String> reqData) throws Exception {
- return this.closeOrder(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:关闭订单<br>
- * 场景:公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> closeOrder(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_CLOSEORDER_URL;
- }
- else {
- url = WXPayConstants.CLOSEORDER_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:申请退款<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> refund(Map<String, String> reqData) throws Exception {
- return this.refund(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:申请退款<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付<br>
- * 其他:需要证书
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> refund(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_REFUND_URL;
- }
- else {
- url = WXPayConstants.REFUND_URL;
- }
- String respXml = this.requestWithCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:退款查询<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> refundQuery(Map<String, String> reqData) throws Exception {
- return this.refundQuery(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:退款查询<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> refundQuery(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_REFUNDQUERY_URL;
- }
- else {
- url = WXPayConstants.REFUNDQUERY_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:对账单下载(成功时返回对账单数据,失败时返回XML格式数据)<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> downloadBill(Map<String, String> reqData) throws Exception {
- return this.downloadBill(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:对账单下载<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付<br>
- * 其他:无论是否成功都返回Map。若成功,返回的Map中含有return_code、return_msg、data,
- * 其中return_code为`SUCCESS`,data为对账单数据。
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return 经过封装的API返回数据
- * @throws Exception
- */
- public Map<String, String> downloadBill(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_DOWNLOADBILL_URL;
- }
- else {
- url = WXPayConstants.DOWNLOADBILL_URL;
- }
- String respStr = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs).trim();
- Map<String, String> ret;
- // 出现错误,返回XML数据
- if (respStr.indexOf("<") == 0) {
- ret = WXPayUtil.xmlToMap(respStr);
- }
- else {
- // 正常返回csv数据
- ret = new HashMap<String, String>();
- ret.put("return_code", WXPayConstants.SUCCESS);
- ret.put("return_msg", "sdk");
- ret.put("data", respStr);
- }
- return ret;
- }
- /**
- * 作用:交易保障<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> report(Map<String, String> reqData) throws Exception {
- return this.report(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:交易保障<br>
- * 场景:刷卡支付、公共号支付、扫码支付、APP支付
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> report(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_REPORT_URL;
- }
- else {
- url = WXPayConstants.REPORT_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return WXPayUtil.xmlToMap(respXml);
- }
- /**
- * 作用:转换短链接<br>
- * 场景:刷卡支付、扫码支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> shortUrl(Map<String, String> reqData) throws Exception {
- return this.shortUrl(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:转换短链接<br>
- * 场景:刷卡支付、扫码支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> shortUrl(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_SHORTURL_URL;
- }
- else {
- url = WXPayConstants.SHORTURL_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- /**
- * 作用:授权码查询OPENID接口<br>
- * 场景:刷卡支付
- * @param reqData 向wxpay post的请求数据
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> authCodeToOpenid(Map<String, String> reqData) throws Exception {
- return this.authCodeToOpenid(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
- }
- /**
- * 作用:授权码查询OPENID接口<br>
- * 场景:刷卡支付
- * @param reqData 向wxpay post的请求数据
- * @param connectTimeoutMs 连接超时时间,单位是毫秒
- * @param readTimeoutMs 读超时时间,单位是毫秒
- * @return API返回数据
- * @throws Exception
- */
- public Map<String, String> authCodeToOpenid(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
- String url;
- if (this.useSandbox) {
- url = WXPayConstants.SANDBOX_AUTHCODETOOPENID_URL;
- }
- else {
- url = WXPayConstants.AUTHCODETOOPENID_URL;
- }
- String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
- return this.processResponseXml(respXml);
- }
- } // end class
|