-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refund #6
Closed
Closed
Refund #6
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4cbc9cb
添加 订单查询
klausxie b8b5ac6
增加 申请退款接口
klausxie 623d4ac
添加 退款查询接口
klausxie b4f47e4
将退款接口添加到微信工厂
klausxie 5617c4b
为申请退款添加apiclient_cert.p12证书
klausxie 92e2797
.
klausxie 6a18ab9
.
klausxie 1813790
finish
klausxie a486168
little modify
klausxie c6be220
添加消息模板接口
klausxie a01f1bc
添加企业给个人付款接口
klausxie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.github.cuter44.wxpay.reqs; | ||
|
||
import com.github.cuter44.wxpay.WxpayException; | ||
import com.github.cuter44.wxpay.WxpayProtocolException; | ||
import com.github.cuter44.wxpay.resps.ResponseBase; | ||
import org.apache.http.HttpEntity; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||
import org.apache.http.conn.ssl.SSLContexts; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.security.KeyStore; | ||
import java.util.Properties; | ||
|
||
import static com.github.cuter44.wxpay.util.XMLParser.parseXML; | ||
|
||
/** | ||
* Created by Mklaus on 15/4/25. | ||
*/ | ||
public class ClientCustomSSL { | ||
private static final String CERT_PATH = "apiclient_cert.p12"; | ||
|
||
private static ClassLoader cl = ClientCustomSSL.class.getClassLoader(); | ||
|
||
public static final String KEY_RETURN_CODE = "return_code"; | ||
public static final String KEY_RETURN_MSG = "return_msg"; | ||
public static final String KEY_ERR_CODE = "err_code"; | ||
|
||
public static final String VALUE_FAIL = "FAIL"; | ||
|
||
public static ResponseBase getResponseBase(String mch_id,String baseURL,String data) throws Exception{ | ||
String path = cl.getResource(CERT_PATH).toURI().getPath(); | ||
|
||
return getResponseBase(path, mch_id, baseURL, data); | ||
} | ||
|
||
public static ResponseBase getResponseBase(String path,String mch_id,String baseURL,String data) throws Exception { | ||
|
||
if (path == null) { | ||
path = cl.getResource("apiclient_cert.p12").toURI().getPath(); | ||
} | ||
|
||
KeyStore keyStore = KeyStore.getInstance("PKCS12"); | ||
FileInputStream inputStream = new FileInputStream(new File(path)); | ||
|
||
Properties prop = new Properties(); | ||
|
||
try{ | ||
keyStore.load(inputStream,mch_id.toCharArray()); | ||
}finally { | ||
inputStream.close(); | ||
} | ||
|
||
// Trust own CA and all self-signed certs | ||
SSLContext sslcontext = SSLContexts.custom() | ||
.loadKeyMaterial(keyStore, mch_id.toCharArray()) | ||
.build(); | ||
|
||
// Allow TLSv1 protocol only | ||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( | ||
sslcontext, | ||
new String[] { "TLSv1" }, | ||
null, | ||
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); | ||
|
||
CloseableHttpClient httpclient = HttpClients.custom() | ||
.setSSLSocketFactory(sslsf) | ||
.build(); | ||
|
||
try { | ||
HttpPost httpPost = new HttpPost(baseURL); | ||
httpPost.setHeader("Accept-Charset","UTF-8"); | ||
httpPost.setEntity(new StringEntity(data, "UTF-8")); | ||
CloseableHttpResponse response = httpclient.execute(httpPost); | ||
try { | ||
HttpEntity entity = response.getEntity(); | ||
|
||
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); | ||
|
||
prop.putAll(parseXML(content)); | ||
|
||
EntityUtils.consume(entity); | ||
|
||
if (VALUE_FAIL.equals(prop.getProperty(KEY_RETURN_CODE))) | ||
throw( | ||
new WxpayProtocolException( | ||
prop.getProperty(KEY_RETURN_MSG) | ||
)); | ||
|
||
if (VALUE_FAIL.equals(prop.getProperty(KEY_ERR_CODE))) | ||
throw( | ||
new WxpayException( | ||
prop.getProperty(KEY_ERR_CODE) | ||
)); | ||
|
||
return(new ResponseBase(entity.toString(), prop)); | ||
|
||
} finally { | ||
response.close(); | ||
} | ||
}catch (Exception ex) { | ||
throw(new WxpayException(ex)); | ||
}finally { | ||
httpclient.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.github.cuter44.wxpay.reqs; | ||
|
||
import com.github.cuter44.wxpay.resps.OrderQueryResponse; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Created by Mklaus on 15/4/21. | ||
*/ | ||
public class OrderQueryRequest extends RequestBase{ | ||
|
||
public static final String URL_API_BASE = "https://api.mch.weixin.qq.com/pay/orderquery"; | ||
|
||
protected static final String KEY_OUT_TRADE_NO = "out_trade_no"; | ||
protected static final String KEY_TRANSACTION_ID = "transaction_id"; | ||
|
||
public static final List<String> KEYS_PARAM_NAME = Arrays.asList( | ||
"appid", | ||
"mch_id", | ||
"nonce_str", | ||
"out_trade_no", | ||
"transaction_id", | ||
"sign" | ||
); | ||
|
||
//CONSTRUCT | ||
public OrderQueryRequest(Properties prop){ | ||
super(prop); | ||
|
||
return; | ||
} | ||
|
||
//BUILD | ||
@Override | ||
public OrderQueryRequest build() | ||
{ | ||
return (this); | ||
} | ||
|
||
//SIGN | ||
@Override | ||
public OrderQueryRequest sign() throws UnsupportedEncodingException | ||
{ | ||
this.sign(KEYS_PARAM_NAME); | ||
return (this); | ||
} | ||
|
||
// TO_URL | ||
public String toURL() | ||
throws UnsupportedOperationException | ||
{ | ||
throw( | ||
new UnsupportedOperationException("This request does not execute on client side") | ||
); | ||
} | ||
|
||
// EXECUTE | ||
@Override | ||
public OrderQueryResponse execute() | ||
{ | ||
return( | ||
new OrderQueryResponse( | ||
this.execute(URL_API_BASE, KEYS_PARAM_NAME) | ||
)); | ||
} | ||
|
||
/** 商户系统内部的订单号,32个字符内、可包含字母 | ||
*/ | ||
public OrderQueryRequest setOutTradeNo(String outTradeNo) | ||
{ | ||
this.setProperty(KEY_OUT_TRADE_NO, outTradeNo); | ||
|
||
return(this); | ||
} | ||
|
||
/** 微信的订单号, 优先使用 | ||
*/ | ||
public OrderQueryRequest setTransactionId(String transactionId) | ||
{ | ||
this.setProperty(KEY_TRANSACTION_ID,transactionId); | ||
|
||
return (this); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is improper to use File here. Data encapsulated in some virtual source such as java archive(.jar)/URL may not and should not access via File interfaces. In this case, certificates are provided in classpath, which requires you to access it via the "classpath" way. Such like this:
You may refer to javadoc or SO for further information.