Because Android devices generally use wireless payment, we all apply for Alipay wireless fast payment interface.
If the link fails, you can find the fast payment (wireless) service in Alipay official website merchant service module.
Download the integrated development package, and after decompression, I find that there is a client demonstration, that is, a description document. Find Android_SDK in the client demo, which is the Alipay interface and demo you want to use.
Import demo (Alipay _sdk_demo) and (Alipay _lib) into your eclipse, and then you can try to run demo (Alipay _sdk_demo) again. As long as you understand this demo, you will call this Alipay interface. As for how to integrate into your project, the document is very detailed, just follow the document step by step. My suggestion is that before designing your project, learn about this demo and see what data is needed when calling the interface, which is also helpful for your initial data design.
Let's briefly introduce the structure in the interface demonstration.
Open the project and you will find five classes in it.
Among them, Base64.java, Result.java and Rsa.java do not need to be relocated. If you need to use them, just put them directly into your project. If you want to know them, you can also go and see them. The focus is on ExternalPartner.java and Keys.java. Let's talk about Keys.java's class first.
Key.java can only be configured after you successfully apply for Alipay signing. Put it here first. How to configure it is very clear in my notes.
Then the ExternalPartner.java class. This class is actually very simple. When you run this demo program, you will find a lot of product information loaded in listview. Clicking on a product will call the Alipay interface (because Key.java is not configured, it may not be called now). We found the way to click the event in listview, and then found the entrance to call Alipay.
Cage? com . AliPay . Android . MSP . demo; ?
Import? Java . io . io exception; ?
........?
........?
Import? Com.AliPay.android.app.sdk.AliPay; ?
Public? Class? ExternalPartner? Extension? Activities? Artifacts? OnItemClickListener,?
OnClickListener? {?
Public? Static electricity Final? String? Label? =? "Alipay-SDK"; ?
Private? Static electricity Final? int? RQF payment? =? 1; ?
Private? Static electricity Final? int? RQF _ login? =? 2; ?
Private? EditText? Musrid; ?
Private? Button? Mlogon; ?
@ Overwrite?
Public? Invalid? OnCreate (bundle? savedInstanceState)? {?
super . oncreate(savedInstanceState); ?
setContentView(r . layout . external _ partner); ?
init products(); ?
initListView(); ?
}?
/*?
*? (non-Javadoc)?
*?
*? @ See? Android . app . activity # onCreateOptionsMenu(Android . view . menu)?
*/?
@ Overwrite?
Public? Bull? OnCreateOptionsMenu (menu? Menu)? {?
Menu.add (menu. No? Menu. First,? 1,? "quick login"); ?
Return? True; ?
}?
/*?
*? (non-Javadoc)?
*?
*? @ See? Android . app . activity # on options sitem selected(Android . view . menuitem)?
*/?
@ Overwrite?
Public? Bull? onOptionsItemSelected(MenuItem? Item)? {?
Switch? (item.getItemId())? {?
Case? Menu. First of all:
setContentView(r . layout . trust log in); ?
Musrid? =? (EditText)? findViewById(r . id . user _ id); ?
Mlogon? =? (button)? findViewById(r . id . get _ token); ?
mlogon . setonclicklistener(this); ?
Break; ?
}?
Return? Fake; ?
}?
Private? Invalid? initProducts()? {?
What if? (sProducts? ! =? null)?
Return; ?
XmlResourceParser? Parser? =? getResources()。 get XML(r . XML . products); ?
ArrayList & lt products & gt? Product? =? New? ArrayList & lt product & gt (); ?
Product? Product? =? null?
Try it? {?
int? eventType? =? parser . get event type(); ?
What time? (eventType? ! =? XmlPullParser。 END_DOCUMENT)? {?
What if? (eventType? ==? XmlPullParser。 Start _ tab?
& amp& amp? parser.getName()。 equalsIgnoreCase("product "))? {?
Product? =? New? product(); ?
Product theme? =? parser . getattributevalue(0); ?
Products. Body? =? parser . getattributevalue( 1); ?
Product. Price? =? parser . getattributevalue(2); ?
Products.add (products); ?
}?
eventType? =? parser . next(); ?
}?
Sports products? =? New? product[products . size()]; ?
Products.toArray (products); ?
}? Catch? (XmlPullParserException? e)? {?
e . printstacktrace(); ?
}? Catch? (IOException? e)? {?
e . printstacktrace(); ?
}?
}?
//listview click event, which AliPay interface to call?
@ Overwrite?
Public? Invalid? onItemClick(adapter view & lt; ? & gt? arg0,? Opinion? arg 1,? int? Location,?
Dragon? arg3)? {?
Try it? {?
Log.i("ExternalPartner "," onItemClick "); ?
String? Information? =? getNewOrderInfo(position); //This is the order information?
String? Sign? =? Rsa.sign (information,? key Private); //signature encryption order information or something?
Sign? =? URLEncoder.encode (symbol); ?
Information? +=? “& ampsign=\ "? +? Sign? +?" \ " & amp? +? getSignType(); ?
Log.i("ExternalPartner ","Start? Pay "); ?
//? Start? That? Pay. ?
Log.i (tag, "information? =? "? +? info); ?
Final? String? orderInfo? =? Information; ?
New? Thread ()? {?
Public? Invalid? run()? {?
Alipay? Alipay? =? New? Alipay (ExternalPartner.this,? mHandler); //This should be Alipay interface, haha, Alipay now encapsulates many functions, so it saves a lot of code?
//Set to sandbox mode, not set to online environment by default?
//AliPay . set sandbox(true); ?
String? The result? =? Alipay.pay (orderinfo); //This is the returned result. Then you can operate what you want according to this result, and then it's basically over. You can write other functions you want to add at will. Now that Key.java is configured, you can call Express Payment?
//The following codes can be changed to your own or based on them?
Log.i (tag, "What about the result? =? "? +? Results); ?
Leave a message MSG? =? New? message(); ?
MSG. What? =? RQF _ PAY; ?
msg.obj? =? Results; ?
mhandler . sendmessage(msg); ?
}?
}.start(); ?
}? Catch? (exception? ex)? {?
ex . printstacktrace(); ?
toast . make text(external partner . this,? R.string.remote_call_failed,?
Toast. LENGTH_SHORT)。 show(); ?
}?
}?
//How to get the order information?
Private? String? getNewOrderInfo(int? Location)? {?
StringBuilder? sb? =? New? StringBuilder(); ?
sb . append(" partner = \ "); ?
Someone attaches (a key). Default _ Partner); //? Partner id?
Sb addition ("\"&out _ trade _ no = \?
sb . append(getOutTradeNo()); //Is this the order number?
Sb addition ("\" & ampsubject = \?
Someone attached (product [location]). Theme); //This should be the product name, right?
Sb addition ("\" & ampbody = \?
Someone attached (product [location]). Body); //This should be a description of the goods. Refer to demo for details.
Sb addition ("\" & amptotal _ fee = \?
Someone adds (a product [position]). price.replace ("price:",? "")); //This is the amount to be paid. Call and change?
sb.append("? ify _ url = \?
//? Does URL need URL encoding?
sb . append(URL encoder . encode(" http://notify . Java . jpxx . org/index . JSP ")); //The asynchronous notification page of the server, the page that notifies the merchant server after the transaction is completed, and sends the commodity order information to the designated page in the form of post, so the mobile phone client can stay here first without any need? .
Isn't it? This class is very simple and easy to understand, just a listview. The method of calling Alipay interface is in the method of onItemClick (). If you are a button, change it to a button click event. I have written down the main details in my notes. Now, what you need to consider is, what data do you need to provide to the onItemClick () method? String? The data in info. demo is getNewOrderInfo(int? Position) provided by this method, you can provide it yourself or modify it above.
Now, you already know how the code calls the Alipay interface. Next, how to integrate these into your project.