EasyPay(易支付),两分钟集成三种Android支付方式
2017-03-07 本文已影响2908人
KingofGlory
EasyPay(易支付)
screenshot.gifUsage(使用)
step 1
在build.gradle直接引用 :
compile 'com.xgr.easypay:EasyPay:1.0.2'
下载库后作为module导入:
compile project(':easypay')
Or Maven :
<dependency>
<groupId>com.xgr.easypay</groupId>
<artifactId>EasyPay</artifactId>
<version>1.0.2</version>
<type>pom</type>
</dependency>
step 2
银联支付:
配置:无需配置
编码:
private void unionpay(){
//实例化银联支付策略
UnionPay unionPay = new UnionPay();
//构造银联订单实体。一般都是由服务端直接返回。测试时可以用Mode.TEST,发布时用Mode.RELEASE。
UnionPayInfoImpli unionPayInfoImpli = new UnionPayInfoImpli();
unionPayInfoImpli.setTn("814144587819703061900");
unionPayInfoImpli.setMode(Mode.TEST);
//策略场景类调起支付方法开始支付,以及接收回调。
EasyPay.pay(unionPay, this, unionPayInfoImpli, new IPayCallback() {
@Override
public void success() {
toast("支付成功");
}
@Override
public void failed() {
toast("支付失败");
}
@Override
public void cancel() {
toast("支付取消");
}
});
}
微信支付:
配置:(具体可参考demo项目)
- 在你的项目包名(applicationId:com.xxx.xxx)目录下建立.wxapi(如com.xxx.xxx.wxapi)目 录。在目录下新建WXPayEntryActivity.java,继承WXPayEntryBaseActivity.java,实现getWXAppId()方法。
public class WXPayEntryActivity extends WXPayEntryBaseActivity {
@Override
public String getWXAppId() {
return "appid";
}
}
- 在AndroidManifest.xml中注册上述Activity.
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
编码:
private void wxpay(){
//实例化微信支付策略
String wxAppId = "";
WXPay wxPay = WXPay.getInstance(this,wxAppId);
//构造微信订单实体。一般都是由服务端直接返回。
WXPayInfoImpli wxPayInfoImpli = new WXPayInfoImpli();
wxPayInfoImpli.setTimestamp("");
wxPayInfoImpli.setSign("");
wxPayInfoImpli.setPrepayId("");
wxPayInfoImpli.setPartnerid("");
wxPayInfoImpli.setAppid("");
wxPayInfoImpli.setNonceStr("");
wxPayInfoImpli.setPackageValue("");
//策略场景类调起支付方法开始支付,以及接收回调。
EasyPay.pay(wxPay, this, wxPayInfoImpli, new IPayCallback() {
@Override
public void success() {
toast("支付成功");
}
@Override
public void failed() {
toast("支付失败");
}
@Override
public void cancel() {
toast("支付取消");
}
});
}
支付宝支付:
配置:无需配置。
编码:
private void alipay(){
//实例化支付宝支付策略
AliPay aliPay = new AliPay();
//构造支付宝订单实体。一般都是由服务端直接返回。
AlipayInfoImpli alipayInfoImpli = new AlipayInfoImpli();
alipayInfoImpli.setOrderInfo("");
//策略场景类调起支付方法开始支付,以及接收回调。
EasyPay.pay(aliPay, this, alipayInfoImpli, new IPayCallback() {
@Override
public void success() {
toast("支付成功");
}
@Override
public void failed() {
toast("支付失败");
}
@Override
public void cancel() {
toast("支付取消");
}
});
}
没错,就是这样,这就搞定了。
由于水平有限,难免会有错误。请大家多多指教。
有任何问题请在issues里面留言交流。Issues.
Contact Me(联系我)
- Email : kingofglory@yeah.net
- Weibo : @King的沉积时代
License
MIT License
Copyright (c) 2017 kingofglory
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.