Payment Treasure Mobile Payment SDK2.0 application Actual combat summary

Source: Internet
Author: User
Tags base64 manual error code stub

Temporary Accept Alipay Payment task, the original study of the old version, later found that the new version is more simple and clear optimization, the use of the latest version, see the old version of the number of people, the new version of the less, I this most refined through practice drops, and common progress.

1. Download the mobile Payment Interface SDK2.0 Standard Edition, extract:

(1) from the client Alipay-sdk-common folder to remove alipaysdk.jar , Alipaysecsdk.jar, Alipayutdid.jar into the new project Libs, android4.0 only put into the free manual import, lower than this version of the manual import by the old method.

(2) Remove Base64.java, Result.java, Signutils.java from the client demo and place them in SRC, corresponding to the support.

2. Permission to open:

  code is as follows copy code
< 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"/>
<uses-permission android: Name= "Android.permission.ACCESS_COARSE_LOCATION"/>  
<uses-permission android:name= " Android.permission.WRITE_APN_SETTINGS "/>



3. Payment Interface Call:

The code is as follows Copy Code
/**
* Payment ORDER BY Alipay
*void
* @exception
* @since 1.0.0
*/
public void Pay (final string orderInfo, final string sign) {

Threadmanager.starttaskthread (New Runnable () {

@Override
public void Run () {
TODO auto-generated Method Stub
Constructing Paytask objects
Paytask Alipay = new Paytask (activity);
Stitching into full payment information (Order + signature)
Final String payinfo = orderInfo + "&sign=" "+ Sign +" "" + "&"
+ Getsigntype ();
Call Payment Interface
String result = Alipay.pay (payinfo);
Payresult = Base64.encode (Result.getbytes ());

Result RTL = new result (result); Resolve Payment Results
Textutils.equals (Resultstatus, "9000")
Payment result error code:
/*9000: Successful order payment
* 8000: In Process ("Payment result confirmation") on behalf of the payment results due to the payment channel or system reasons are still waiting for payment results confirm that the final transaction is successful with the service-side asynchronous notification (small probability state)
* 4000: Failed to pay the order
* 6001: The user canceled halfway
* 6002: Network connection Error * *
Final String resultstatus = rtl.resultstatus; Payment error code
GOLOLOG.D (Alipay_pay_key, "Get ALIPAY result Status:" + Resultstatus);
if (activity!= null) {
Activity.runonuithread (New Runnable () {

@Override
public void Run () {
TODO auto-generated Method Stub
if (Textutils.equals (Resultstatus, "9000")) {//9000: Order payment Successful
Toast.maketext (activity, "pay success",
Toast.length_short). Show ();
}else {
To judge that a resultstatus is not "9000" means it may fail to pay
"8000" on behalf of the payment results due to the payment channel or system reasons are still waiting for payment results confirm that the final transaction is successful with the service-side asynchronous notification (small probability state)
if (Textutils.equals (Resultstatus, "8000")) {
Toast.maketext (activity, "payment result confirmation",
Toast.length_short). Show ();

} else {
Toast.maketext (activity, "failure to pay",
Toast.length_short). Show ();

}
}

}
});
}
}
});
}



4. Personal interface Call:

OrderInfo Order Content

Strsign Signature

The code is as follows Copy Code
Alipay pay
private void Toalipay () {
TODO auto-generated Method Stub

String orderInfo = Orderbean.getorderinfo ();
String strsign = Orderbean.getordersign ();

Alipaypayhandler.pay (OrderInfo, strsign);

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.