JPay 微信和支付宝支付的二次封装 项目简介
JPay对微信App支付、支付宝App支付的二次封装,对外提供一个相对简单的接口以及支付结果的回调 使用方法1、引入 compile 'com.javen205.jpay:jpaysdk:latest.release.here'2. Android Manifest配置2.1权限声明<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />2.2注册activityapplication节点添加如下类容<!-- 微信支付 -->
<activity
android:name="com.javen205.jpay.weixin.WXPayEntryActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity-alias
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:targetActivity="com.javen205.jpay.weixin.WXPayEntryActivity" />
<!-- 微信支付 end -->
<!-- alipay sdk begin -->
<activity
android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="com.alipay.sdk.app.H5AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<!-- alipay sdk end --> 3. 发起支付3.1 微信支付JPay.getIntance(mContext).toPay(JPay.PayMode.WXPAY, payParameters, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT).show()
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "支付失败>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "取消了支付", Toast.LENGTH_SHORT).show();
}
});payParameters 为JSON字符串格式如下: {
"appId": "",
"partnerId": "",
"prepayId": "",
"sign": "",
"nonceStr" : "",
"timeStamp": ""
}或者JPay.getIntance(mContext).toWxPay(appId, partnerId, prepayId, nonceStr, timeStamp, sign, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "支付失败>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "取消了支付", Toast.LENGTH_SHORT).show();
}
});3.2 支付宝支付 JPay.getIntance(mContext).toPay(JPay.PayMode.ALIPAY, orderInfo, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "支付失败>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "取消了支付", Toast.LENGTH_SHORT).show();
}
});或者 Alipay.getInstance(mContext).startAliPay(orderInfo, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
}
@Override
public void onPayError(int error_code, String message) {
}
@Override
public void onPayCancel() {
}
});4.案例的使用 appId以及相关的key我们都从服务端获取4.1 客户端使用说明 1. 将`AndroidManifest.xml` 的包名修改为申请应用的包名 2. 将应用中的`build.gradle`的 `applicationId`修改为申请应用的包名 3. 测试的时候修改默认的签名key将key复制到项目的根目录(app)中并修改`buildTypes` 配置如下 signingConfigs {
release {
storeFile file("wxkey")
storePassword '123456'
keyAlias '1'
keyPassword '123456'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
}
}4.2 服务端使用说明1. 开源项目地址weixin_guide2. 开源项目如何下载、如何导入到IDE 参考之前写的文章微信公众号之项目导入3. 微信支付服务端具体实现在`com.javen.weixin.controller.WeixinPayController.java` 类中的`appPay()`4. 支付宝支付服务端具体实现在`com.javen.alipay.AliPayController.java` 类中的`appPay()`4.3 参考资料微信、支付宝APP支付详细介绍参考资料 博客地址[Android版-微信APP支付][Android版-支付宝APP支付][支付宝Wap支付你了解多少?]
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />2.2注册activityapplication节点添加如下类容<!-- 微信支付 -->
<activity
android:name="com.javen205.jpay.weixin.WXPayEntryActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity-alias
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:targetActivity="com.javen205.jpay.weixin.WXPayEntryActivity" />
<!-- 微信支付 end -->
<!-- alipay sdk begin -->
<activity
android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<activity
android:name="com.alipay.sdk.app.H5AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
<!-- alipay sdk end --> 3. 发起支付3.1 微信支付JPay.getIntance(mContext).toPay(JPay.PayMode.WXPAY, payParameters, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT).show()
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "支付失败>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "取消了支付", Toast.LENGTH_SHORT).show();
}
});payParameters 为JSON字符串格式如下: {
"appId": "",
"partnerId": "",
"prepayId": "",
"sign": "",
"nonceStr" : "",
"timeStamp": ""
}或者JPay.getIntance(mContext).toWxPay(appId, partnerId, prepayId, nonceStr, timeStamp, sign, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "支付失败>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "取消了支付", Toast.LENGTH_SHORT).show();
}
});3.2 支付宝支付 JPay.getIntance(mContext).toPay(JPay.PayMode.ALIPAY, orderInfo, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "支付成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "支付失败>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "取消了支付", Toast.LENGTH_SHORT).show();
}
});或者 Alipay.getInstance(mContext).startAliPay(orderInfo, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
}
@Override
public void onPayError(int error_code, String message) {
}
@Override
public void onPayCancel() {
}
});4.案例的使用 appId以及相关的key我们都从服务端获取4.1 客户端使用说明 1. 将`AndroidManifest.xml` 的包名修改为申请应用的包名 2. 将应用中的`build.gradle`的 `applicationId`修改为申请应用的包名 3. 测试的时候修改默认的签名key将key复制到项目的根目录(app)中并修改`buildTypes` 配置如下 signingConfigs {
release {
storeFile file("wxkey")
storePassword '123456'
keyAlias '1'
keyPassword '123456'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
}
}4.2 服务端使用说明1. 开源项目地址weixin_guide2. 开源项目如何下载、如何导入到IDE 参考之前写的文章微信公众号之项目导入3. 微信支付服务端具体实现在`com.javen.weixin.controller.WeixinPayController.java` 类中的`appPay()`4. 支付宝支付服务端具体实现在`com.javen.alipay.AliPayController.java` 类中的`appPay()`4.3 参考资料微信、支付宝APP支付详细介绍参考资料 博客地址[Android版-微信APP支付][Android版-支付宝APP支付][支付宝Wap支付你了解多少?]