Skip to content
/ easywx Public

一个轻量级的微信公众号API开发工具包

License

Notifications You must be signed in to change notification settings

yydf/easywx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easywx

Maven Central GitHub release license Jar Size

环境

  • JDK 7

如何使用

  • 添加dependency到POM文件::
<dependency>
    <groupId>cn.4coder</groupId>
    <artifactId>easywx</artifactId>
    <version>0.0.4</version>
</dependency>
  • 如果用到微信的退款功能,需添加bcprov进行解密
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk16</artifactId>
    <version>1.46</version>
</dependency>
  • 编码:
//注册公众号
WXApi.forMP(appId, appSecret);
System.out.println(WXApi.mp().getAccessToken());
System.out.println(WXApi.mp().createQrcode("test"));

//注册公众号支付
WXApi.mp().forPayment(mchId, apiKey, callbackUrl);
//生成预付单
System.out.println(WXApi.mpPay().createUnifiedOrder(UnifiedOrder.test()));

//获取支付的通知
@Request(value = "/callback", method = HttpMethod.POST)
public String callback() {
	try {
		//如果有退款通知,则添加
		Security.addProvider(new BouncyCastleProvider());
		PayResult result = WXApi.appPay().callback(request.getReader());
		if (result != null) {
			//service.updateStatus(result);
			return PayResult.SUCCESS;
		}
	} catch (IOException e) {
		logger.error("Callback faild", e);
	}
	return PayResult.FAIL;
}

About

一个轻量级的微信公众号API开发工具包

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages