UnionPay payment is also a commonly used payment function, here is a simple introduction to Android app if short-term rapid application of this aspect of things. Directly on the code:
1. Import the UnionPay payment dependency package:
2. Increase the resource bundle in the Res directory:
3. Configure the Androidmanifest.xml file configuration to open activity:
<activity android:name= "com.unionpay.uppay.PayActivity" android:configchanges= "orientation| Keyboardhidden " android:excludefromrecents=" true " android:label=" @string/app_name " android: screenorientation= "Portrait" android:windowsoftinputmode= "Adjustresize"/>
at this point, our project environment is ready. (Please refer to the UnionPay test document for the above documents. )Androiddemo of the catalogue);
UnionPay Payment Code 3 steps:
1. Get TN number 2. Request Control Interface (payactivity)
3.ActivityResult Processing Payment Results (but the result is not necessarily correct, because the UnionPay system is asynchronously returned to the server and our app is asynchronous simultaneously)
Here I take the test interface as an example
/** *unionpay Test * * @author Lean @date: 2014-8-8 */public class Mainactivity extends Activity implements Runnable {PR Ivate string mmode = "01";//Set Test mode: 01 for test 00 for formal environment private static final String tn_url_01 = "http://202.101.25.178:8080/sim/g ETTN ";//The TN interface for our app that you need to implement in your background private Handler mhandler=new Handler () {public void Handlemessage (android.os.Message msg) {String tn = ""; if (msg.obj = = NULL | | (String) msg.obj). Length () = = 0) {Alertdialog.builder Builder = new Alertdialog.builder (mainactivity.this); Builder.settitle ("error Prompt"); Builder.setmessage ("Network connection failed, please try again!"); Builder.setnegativebutton ("OK", new Dialoginterface.onclicklistener () {@Overrid e public void OnClick (Dialoginterface dialog, int which) {Dialog.dismis S (); } }); Builder.create (). Show (); } else {tn = (StRing) Msg.obj; Dostartunionpayplugin (Mainactivity.this, TN, mmode); }}};/** * Start payment interface */public void Dostartunionpayplugin (activity activity, string tn, String mode) {Uppayassistex.sta Rtpaybyjar (activity, payactivity.class, NULL, NULL, TN, mode); } @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); new Thread (Mainactivity.this). Start (); @Overridepublic void Run () {string tn = Null;inputstream is;try {string url = tn_url_01; URL myurl = new URL (URL); URLConnection Ucon = Myurl.openconnection (); Ucon.setconnecttimeout (120000); is = Ucon.getinputstream (); int i =-1; Bytearrayoutputstream BAOs = new Bytearrayoutputstream (), while ((i = Is.read ())! =-1) {baos.write (i);} TN = baos.tostring (); Is.close (); Baos.close ();} catch (Exception e) {e.printstacktrace ();} Message msg = Mhandler.obtainmessage (); msg.obj = Tn;mhandler.sendmessage (msg);} @Overrideprotected void OnactivityresulT (int requestcode, int resultcode, Intent data) {if (data = = null) {return;} String msg = ""; */* The payment control returns a string: Success, fail, and cancel respectively for payment success, payment failure, payment cancellation */string str = Data.getextras (). getString ("Pay_ Result "); LOG.V ("Zftphone", "2" +data.getextras () getString ("Merchantorderid")), if (Str.equalsignorecase ("Success")) {msg = " Payment Success! ";} else if (str.equalsignorecase ("fail")) {msg = "Payment failed! ";} else if (Str.equalsignorecase ("Cancel")) {msg = "user canceled payment";} Payment complete, deal with your own business logic!}
Tip: When you do this, you have to make sure that you have a cow-to-man support team that can accept new things and condemn the customer service at UnionPay to say!