UnionPay Payment Integration----Android

Source: Internet
Author: User

Reprint to: http://blog.csdn.net/wcsandlili/article/details/53467855

I am also a novice, to write this blog just hope that the future of the brothers little Detour, online tutorials a lot, but I think it is not clear enough, may not have done to see half a day to understand, nonsense not to say, directly talk about my integration process it!

First of all, to enter the UnionPay open platform, to tell the truth, this link to find a little pit dad, not very good search, directly affixed to the https://open.unionpay.com/ajweb/help/file/techFile?productId=3

Enter the website, the official demo download down, to tell the truth, I feel that the official demo is a bit redundant, directly follow my steps to it:

Create your own project, work in the project directory, create an assert asset file in the main folder, Put the Data.bin file in, create the Jnilibs folder, the C language so library copy in, these files in the official compressed package can be found, patience to find, the actual effect such as

Don't forget to copy the Uppayassistex.jar into the Lib library.

Permissions don't forget to add

<!--UnionPay privileges--<uses-Permission Android:name= "Android.permission.INTERNET"/> <uses-Permission Android:name= "Android.permission.ACCESS_NETWORK_STATE"/> <uses-Permission Android:name= "Android.permission.CHANGE_NETWORK_STATE"/> <uses-Permission Android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name= "android.permission.READ_ Phone_state "/> <uses-Permission Android:name= "Android.permission.ACCESS_WIFI_STATE"/> <!--<!-If you choose to integrate smart card mode (that is, sdkpro), you need to define the following permissions in addition –>--> <uses -Permission Android:name= "Android.permission.RECORD_AUDIO"/> <uses-Permission Android:name= "Android.permission.MODIFY_AUDIO_SETTINGS"/> <uses-Permission Android:name= "Org.simalliance.openmobileapi.SMARTCARD"/>

UnionPay activity also don't forget to register

<!--UnionPay payment app-->        <activity android:name= "com.unionpay.uppay.PayActivity"          android:label= "@string/app_name"          android:screenorientation= "Portrait" android:configchanges= "orientation| Keyboardhidden "          android:excludefromrecents=" true "          android:windowsoftinputmode=" Adjustresize "/>  



According to the above writing, the official demo also has, you can directly copy on the line

"HTTP://101.231.204.84:8091/SIM/GETACPTN"

Using the above URL to generate a TN serial number, our app ' End payment depends on this serial number (note that in the actual project, this TN journal number is back to us)

Here is the main code for the payment, the main code for calling the payment is the Startpaybyjar in the Click event
/***************************************************************** * Mmode parameter explanation: "00"-Start UnionPay formal Environment "01"-Connect UnionPay test environment *****************************************************************/      Private FinalString Mmode = "01"; PrivateButton BT; Private Static FinalString tn_url_01 = "HTTP://101.231.204.84:8091/SIM/GETACPTN"; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);          Setcontentview (R.layout.activity_main);      Initview (); }        Private voidInitview () {BT=(Button) Findviewbyid (R.ID.BT); Bt.setonclicklistener ( This); }          //Callback@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {          /************************************************* * Step 3: Handle the payment results returned by the Silver Teaming machine payment control ************************** **********************/          if(Data = =NULL) {              return; } String msg= ""; /** Payment Control return String: Success, fail, cancel respectively on behalf of payment success, payment failure, payment cancellation*/String str= Data.getextras (). getString ("Pay_result"); if(Str.equalsignorecase ("Success")) {              //after successful payment, if there is result_data in the extra, remove the checksum//result_data structure See C) result_data parameter description            if(Data.hasextra ("Result_data") {String result= Data.getextras (). getString ("Result_data"); //try {//jsonobject Resultjson = new Jsonobject (result); //String sign = resultjson.getstring ("sign"); //String dataorg = resultjson.getstring ("Data"); //                    //Certificate of Examination and background examination Visa//                    //Verify here, merchants need to send to the merchant backstage to do check//boolean ret = verify (dataorg, sign, mmode); //if (ret) {//                        //after validation is passed, the payment results are displayed//msg = "Payment succeeded!"                  "; //} else {//                        //processing after validation is not passed//                        //We recommend that you check the payment results through the merchant background//msg = "Payment failed!"                  "; //                    }                  //} catch (Jsonexception e) {//                }                  //} else {//No signature information received//We recommend that you check the payment results through the merchant background//msg = "Payment succeeded!"                  "; //            }  msg = "Payment succeeded!" "; } Else if(Str.equalsignorecase ("fail") ) {msg= "Payment failed!" "; } Else if(Str.equalsignorecase ("Cancel") ) {msg= "User Canceled payment"; } toast.maketext ( This, MSG, Toast.length_short). Show (); System.out.println ("Notice of payment results" +msg); Alertdialog.builder Builder=NewAlertdialog.builder ( This); Builder.settitle ("Notice of payment results");              Builder.setmessage (msg); Builder.setinversebackgroundforced (true); //Builder.setcustomtitle (); Builder.setnegativebutton ("OK",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)                  {Dialog.dismiss ();              }              });          Builder.create (). Show (); }} @Override Public voidOnClick (View v) {/************************************************* * Step 2: Start payment plugin via UnionPay tool class ****************************** ******************/Uppayassistex.startpaybyjar ( This, Payactivity.class,NULL,NULL,                  "201612051739317670088", Mmode); } 

The method above is to pay the callback method, you can write your own logic in the callback

This is just a test demo, if in their actual project, to change the above mode of 01 to 00;TN account Request backend interface back to us, using the TN account to achieve the function of payment

Younger brother rookie A, the big God may feel too redundant, write this blog one is to make a note for themselves, the second is to help and I like in the development of this road in the struggle of the brothers! If there's something wrong in the middle, please.

UnionPay Payment Integration----Android

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.