JPay
Second encapsulation of WeChat App Payment and Alipay App Payment, providing a relatively simple interface and callback of payment results
GitHub:https://github.com/Javen205/JPay
OsChina:http://git.oschina.net/javen205/JPay
Usage method
1. Introduction
compile 'com.javen205.jpay:jpaysdk:latest.release.here'
2. Android Manifest Configuration
2.1 Permission Statement
<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 Register activity
The application node adds the following class contents
<!-- WeChat Payment -->
<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" />
<!-- WeChat Payment 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. Initiate payment
3.1 WeChat Payment
JPay.getIntance(mContext).toPay(JPay.PayMode.WXPAY, payParameters, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "Successful Payment", Toast.LENGTH_SHORT).show()
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "Payment Failed>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "Payment Cancelled", Toast.LENGTH_SHORT).show();
}
});
payParameters are in JSON string format as follows:
{
"appId": "",
"partnerId": "",
"prepayId": "",
"sign": "",
"nonceStr" : "",
"timeStamp": ""
}
perhaps
JPay.getIntance(mContext).toWxPay(appId, partnerId, prepayId, nonceStr, timeStamp, sign, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "Successful Payment", Toast.LENGTH_SHORT).show();
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "Payment Failed>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "Payment Cancelled", Toast.LENGTH_SHORT).show();
}
});
3.2 Alipay Payment
JPay.getIntance(mContext).toPay(JPay.PayMode.ALIPAY, orderInfo, new JPay.JPayListener() {
@Override
public void onPaySuccess() {
Toast.makeText(mContext, "Successful Payment", Toast.LENGTH_SHORT).show();
}
@Override
public void onPayError(int error_code, String message) {
Toast.makeText(mContext, "Payment Failed>"+error_code+" "+ message, Toast.LENGTH_SHORT).show();
}
@Override
public void onPayCancel() {
Toast.makeText(mContext, "Payment Cancelled", Toast.LENGTH_SHORT).show();
}
});
perhaps
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. Use of cases
appId and related key s are all available from the server
4.1 Instructions for client use
- Modify the package name of AndroidManifest.xml to the package name of the application
- Modify the application Id of build.gradle in the application to the package name of the application
- Modify the default signature key when testing
Copy the key into the project's root directory (app) and modify the buildTypes configuration as follows
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 Service-side instructions
- Open source project address weixin_guide
- How open source projects download and import articles written before IDE references WeChat Public Number Project Import
- The WeChat payment server implements appPay() in the com.javen.weixin.controller.WeixinPayController.java class.
- Alipay Payment Server implements appPay() in the com.javen.alipay.AliPayController.java class.
4.3 References
WeChat, Alipay APP Payment Detailed Introduction Reference Blog Address
Android Version-WeChat APP Payment
Android Version - Alipay APP Payment
How much do you know about Alipay Wap Payment?
Amway
WeChat Public Number Development: Subscription Number, Service Number
AndroidStudio Multi-Channel Packaging
Android relies on management and private service building
Android Studio uploads aar(Library) to JCenter
If in doubt, please leave a message