Skip to content

Commit

Permalink
Merge branch 'merge-issue-6'
Browse files Browse the repository at this point in the history
fix PR #6
+ wxpay/OrderQuery
+ wxpay/Refund
+ wxpay/RefundQuery
  • Loading branch information
cuter44 committed May 30, 2015
2 parents e4daf28 + e3cff93 commit 5d9c616
Show file tree
Hide file tree
Showing 20 changed files with 1,187 additions and 31 deletions.
15 changes: 3 additions & 12 deletions doc/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
<url-pattern>/notify.api</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>GetOpenId</servlet-name>
<servlet-class>com.github.cuter44.wxpay.servlet.GetOpenId</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GetOpenId</servlet-name>
<url-pattern>/get-openid.api</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>JSAPISigner</servlet-name>
<servlet-class>com.github.cuter44.wxpay.servlet.JSAPISigner</servlet-class>
Expand All @@ -47,7 +38,7 @@

<servlet>
<servlet-name>SnsapiBase</servlet-name>
<servlet-class>com.github.cuter44.wxpay.servlet.SnsapiBase</servlet-class>
<servlet-class>com.github.cuter44.wxmp.servlet.SnsapiBase</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SnsapiBase</servlet-name>
Expand All @@ -56,7 +47,7 @@

<servlet>
<servlet-name>SnsapiUserinfo</servlet-name>
<servlet-class>com.github.cuter44.wxpay.servlet.SnsapiUserinfo</servlet-class>
<servlet-class>com.github.cuter44.wxmp.servlet.SnsapiUserinfo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SnsapiUserinfo</servlet-name>
Expand All @@ -65,7 +56,7 @@

<servlet>
<servlet-name>JSSDKConfig</servlet-name>
<servlet-class>com.github.cuter44.wxpay.servlet.JSSDKConfig</servlet-class>
<servlet-class>com.github.cuter44.wxmp.servlet.JSSDKConfig</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JSSDKConfig</servlet-name>
Expand Down
3 changes: 2 additions & 1 deletion src/com/github/cuter44/wxmp/reqs/WxmpRequestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ protected static CloseableHttpClient buildHttpClient(SSLContext ctx)
{
HttpClientBuilder hcb = HttpClientBuilder.create()
.disableAuthCaching()
.disableCookieManagement();
.disableCookieManagement()
.setSslcontext(ctx);

return(hcb.build());
}
Expand Down
18 changes: 17 additions & 1 deletion src/com/github/cuter44/wxmp/util/CertificateLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.security.cert.*;
import javax.net.ssl.*;
import java.io.*;
import java.util.MissingResourceException;

/** Transient tool-object to load certificate and generate ssl-context
* Code adapted from nyafx/crypto.
Expand Down Expand Up @@ -100,8 +101,10 @@ public CertificateLoader loadTrusts(String ... resourcePaths)
while (buffer.available() > 0)
{
Certificate cert = crtFactory.generateCertificate(buffer);
System.out.println(cert);
this.trusts.setCertificateEntry("cert-"+System.currentTimeMillis(), cert);

System.out.println("Trusts:");
System.out.println(cert);
}

buffer.close();
Expand All @@ -126,13 +129,26 @@ public CertificateLoader loadIdentification(String resourcePath, String passphra
InputStream stream = this.getClass()
.getResourceAsStream(resourcePath);

if (stream == null)
throw(new MissingResourceException("Load identification failed.", CertificateLoader.class.getName(), resourcePath));

this.identification = KeyStore.getInstance("PKCS12");
this.identification.load(stream, passphrase.toCharArray());

this.passphrase = passphrase;

//System.out.println("Identification:");
//Enumeration<String> aliases = this.identification.aliases();
//while (aliases.hasMoreElements())
//{
//String alias = aliases.nextElement();
//System.out.println(alias);
//System.out.println(this.identification.getCertificate(alias));
//}
}
catch (Exception ex)
{
//ex.printStackTrace();
throw(new RuntimeException(ex));
}

Expand Down
34 changes: 34 additions & 0 deletions src/com/github/cuter44/wxpay/constants/RefundStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.cuter44.wxpay.constants;

/** RefundState
* @since 0.4.1
*
*/
public enum RefundStatus
{
/** code=0, NOTSURE—未确定,需要商户原退款单号重新发起
*/
NOTSURE(0),
/** code=1, PROCESSING—退款处理中
*/
PROCESSING(1),

/** code=16, SUCCES—退款成功
*/
SUCCESS(16),

/** code=-1, FAIL—退款失败
*/
FAIL(-1),

/** code=-2, CHANGE—转入代发,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,资金回流到商户的现金帐号,需要商户人工干预,通过线下或者财付通转账的方式进行退款。
*/
CHANGE(-2);

public byte code;

private RefundStatus(int code)
{
this.code = (byte)code;
}
}
51 changes: 51 additions & 0 deletions src/com/github/cuter44/wxpay/constants/TradeState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.cuter44.wxpay.constants;

/** TradeState
* @since 0.4.1
*
* Notice that <code>code</code> is NOT officially defined by wx.
* And since wx does not provide a status diagram, this distribution is a temporary solution.
* It may be changed in later version. Take consideration before using them.
*/
public enum TradeState
{
/** code=0, NOTPAY—未支付
*/
NOTPAY(0),
/** code=1, NOPAY--未支付(输入密码或确认支付超时)
*/
NOPAY(1),

/** code=2, USERPAYING--用户支付中
*/
USERPAYING(2),

/** code=16, SUCCESS—支付成功
*/
SUCCESS(16),

/** code=32, REFUND—转入退款
*/
REFUND(32),

/** code=64, REVOKED—已撤销
* This is an unclear state.
*/
REVOKED(64),

/** code=-1, PAYERROR--支付失败(其他原因,如银行返回失败)
*/
PAYERROR(-1),

/** code=-128, CLOSED—已关闭
*/
CLOSED(-128);


public byte code;

private TradeState(int code)
{
this.code = (byte)code;
}
}
2 changes: 1 addition & 1 deletion src/com/github/cuter44/wxpay/constants/WxpayErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static WxpayErrorCode forCode(int code)
public static WxpayErrorCode forName(String name)
{
return(
Enum.valueOf(WxpayErrorCode.class, name)
WxpayErrorCode.valueOf(name)
);
}

Expand Down
95 changes: 95 additions & 0 deletions src/com/github/cuter44/wxpay/reqs/OrderQuery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.github.cuter44.wxpay.reqs;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import com.github.cuter44.wxpay.resps.OrderQueryResponse;
import com.github.cuter44.wxpay.WxpayException;
import com.github.cuter44.wxpay.WxpayProtocolException;

/**
* Created by Mklaus on 15/4/21.
*/
public class OrderQuery extends WxpayRequestBase{

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 OrderQuery(Properties prop){
super(prop);

return;
}

//BUILD
@Override
public OrderQuery build()
{
return(this);
}

//SIGN
@Override
public OrderQuery 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()
throws WxpayException, WxpayProtocolException, IOException
{
String url = URL_API_BASE;
String body = this.toXml(KEYS_PARAM_NAME);

String respXml = this.executePostXML(url, body);

return(new OrderQueryResponse(respXml));
}

/** 商户系统内部的订单号,32个字符内、可包含字母
*/
public OrderQuery setOutTradeNo(String outTradeNo)
{
this.setProperty(KEY_OUT_TRADE_NO, outTradeNo);

return(this);
}

/** 微信的订单号,优先使用
*/
public OrderQuery setTransactionId(String transactionId)
{
this.setProperty(KEY_TRANSACTION_ID,transactionId);

return (this);
}
}
Loading

0 comments on commit 5d9c616

Please sign in to comment.