Android payment quick integration case and effective solution for returned values-1, android-1
After a merchant applies to develop an application on the open platform, the open platform will generate a unique APPID for the APP. To ensure payment security, you need to bind the merchant application package name and application signature on the open platform. After the application is set, you can initiate the payment normally. This article explains the Android payment quick integration case and effectively solves the returned value-1.
Next we will refer to the official APP development steps to integrate the payment function step by step:
1. Introduce the JAR package into the merchant APP project, which can be obtained from the official payment demo.
2. Write the code for making the payment.
The official code is as follows:
Note:
final IWXAPI msgApi = WXAPIFactory.createWXAPI(context, null);
Please change the code above officially provided to the following code:
final IWXAPI msgApi = WXAPIFactory.createWXAPI(this,"wxd930ea5d5a258f4f", false);
3. Payment result callback
"Refer to the SDK Sample, in the net. sourceforge. simcpux. WXPayEntryActivity class is implemented in the wxapi package path (inconsistent package names or class names will cause callback failure). For example, my package name is com.cn. cwvs. fruit:
The WXPayEntryActivity reference code is provided here (Please use it with the official payment demo ):
Public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {private IWXAPI api; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. pay_result); api = wxapifacloud. createWXAPI (this, Constant. WEIXIN_APPID); api. handleIntent (getIntent (), this) ;}@ Override protected void onNewIntent (Intent intent) {super. onNewInt Ent (intent); setIntent (intent); api. handleIntent (intent, this) ;}@ Override public void onReq (BaseReq req) {}@ Override public void onResp (BaseResp resp) {int code = resp. errCode; switch (code) {case 0: // interface break after successful payment; case-1: ToastUtils. showToast (getApplicationContext (), "signature error, unregistered APPID, incorrect Project Settings APPID, mismatch between registered APPID and settings, and your account exception. "); Break; case-2: // interface break after the user cancels the payment;} finish (); // subsequent payment operations, failed, succeeded, canceled }}
4. Configure the callback activity in the configuration file.
Now, the integration of the payment Android client has been completed.
Note that if the error code is always-1, try the following solution:
1. package with the submitted signature's keystore File
2. Cleaned Cache
3. Modify the official code according to the preceding notes.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.