Essentials of Android development of micro-letter app payment function _android

Source: Internet
Author: User
Tags error code

Basic concepts

The package name is worth your app package, set up when you create the project, and it needs to be set up on the micro-credit payment platform.

The signature refers to the MD5 of the signature file that you use when you generate the APK, remove: All lowercase, need to set up on the micro-credit payment platform.

In the debugging phase, the signature file can be used for debugging debug.keystore , the signature can be viewed directly from Eclipse, or the installation opens the input package name for viewing.

It must be posted on the micro-credit payment platform to set the signature value for the publication.

The official demo inside content is not all is necessary, even only need to have Libammsdk.jar is enough, Androidmanifest.xml also don't need to configure.

Androidmanifest.xml configuration and Wxpayentryactivity.java only in order to be able to get payment callback, you can not go to the tube, first debugging can be launched to pay.

Copy the Libammsdk.jar to the Libs of your project and add a jar reference.

To initiate a payment request in the code:

Iwxapi API = Wxapifactory.createwxapi (this, values.wxpayappid);
Api.registerapp (VALUES.WXPAYAPPID); Register AppID, this sentence is very important, otherwise will not initiate call

payreq req = new Payreq ();
Req.appid = wxpay.appid;//is Values.wxpayappid, if the two are inconsistent, they cannot initiate payment.
Req.partnerid = json.getstring ("Partnerid");
Req.prepayid = json.getstring ("Prepayid");
Req.noncestr = json.getstring ("Noncestr");
Req.timestamp = json.getstring ("TimeStamp");
Req.packagevalue = json.getstring ("package");
Req.sign = json.getstring ("sign");
Req.extdata = "";//"app data"; Optional

Boolean r = Api.sendreq (req);
if (!r) {
 Toast.maketext (this, "open the micro-letter payment failed!", Toast.length_short). Show ();

The above code in the relevant pre-order ID, signature, timestamp, etc. are returned by the service side, the server in the generation of these values need to pay attention to two times the problem of signing.

Normally the micro-mail client will open the payment page, and then you can start the callback thing again.
Copy the Wxpayentryactivity.java to the Wxapi folder under your project package, such as your package name is Com.xx.shop, then put it under COM.XX.SHOP.WXAPI.
Set Androidmanifest.xml to support callbacks:

<activity
 android:name= ". Wxapi. Wxpayentryactivity "
 android:screenorientation=" Portrait "android:exported=" true "
 android:launchmode=" Singletop ">
 <intent-filter>
  <action android:name=" Android.intent.action.VIEW "/>< Category android:name= "Android.intent.category.DEFAULT"/><data android:scheme= "your AppID"/>
 Intent-filter>/>
</activity>

Wxpayentryactivity.java does not require layout files or can be laid out according to your needs.

For debugging convenience, change the code in the Wxpayentryactivity.java to onResp :

@Override public
void Onresp (Baseresp resp) {
 log.d ("Onpayfinish", "onpayfinish, Errcode =" + Resp.errcode); 
   if (resp.errcode==0) {
  Toast.maketext (this, "pay success!", Toast.length_short). Show ();
 else if (resp.errcode==-1) {
  Toast.maketext (this, "Payment failed!", Toast.length_short). Show ();
 else if (resp.errcode==-2) {
  Toast.maketext (this, "Cancel payment!", Toast.length_short). Show ();

Whether it is possible to pay success or not, if onResp the code can be automatically executed, then the configuration in your androidmanifest.xml is the right one.

If you have a lot of aware on your parameters (for example, your iOS group will be able to pay, you are still in the pit of Android, then see api.registerApp(Values.WXPAYAPPID); if there is, yes, I have to die here, in this case the first (very occasionally) can open the payment interface, the back is not.

Summarize

Micro-letter Why can not give a bit of detailed error code or description, and so on, give a-1, God knows what is meant to be really unpleasant. These are all the things that Android has to do to develop the micro-mail app payment feature, and hopefully this article will help you develop Android.

Related Article

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.