Do a micro-letter payment, download the demo, found and before some changes, v3.0 version, perhaps some friends are groping, here I have successfully paid, not to say, directly into the subject:
First, in the micro-credit development platform to register the account, add the application, fill in the correct package name, the correct signature (MD5 a string of characters colon removed, all lowercase), of course, will also generate AppID and Appsecret are useful! Finally, it will take 300 ocean to open the payment function!
Second, analyze the micro-letter payment Process
Third, interface interaction process
It all reads, and then it's code-writing.
Four, here must have wxapi this package name, and must have wxpayentryactivity this class name
V. Configure relevant information inside the Androidmanifest.xml
<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"/> <!--start the home page--> <activity android:name= " . ui.activity.MainActivity "android:label=" @string/app_name "> <intent-filter> <action Andr
Oid:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter> <intent-filter> <action android:name= "Android.intent.action.VIEW"/> <category android:name= "Android.intent.category.DEFAULT"/> <data android:scheme= "wx487898a262d"
23df3 "/> </intent-filter> </activity>
<activity android:name= ". Wxapi. Wxpayentryactivity "android:exported=" true "android:label=" @string/title_activity_wxpayentry "Android:la Unchmode= "Singletop"/> <receiver android:name= "Wxpay. Appregister "android:permission=" Com.tencent.mm.plugin.permission.SEND "> <intent-filter> ; Action android:name= "Com.tencent.mm.plugin.openapi.Intent.ACTION_REFRESH_WXAPP"/> </intent-filter> &l T;/receiver>/** * First call the interface, to send some basic information as a parameter to the server * For example: Amount fee, user ID, title, etc. * after the success of the call will return the micro-letter required parameters, such as: * Appid,nonc
Estr,package,partnerid,prepayid, * timestamp,sign * Micro-LETTER Payment * * * stringbuffer SB = new StringBuffer ();
Weixinpay Wpay;
Private Alertdialog Mdialog;
Private Alertdialog.builder Builder;
public void Weixinpay () {//through Wxapifactory factory, get Iwxapi Instance API = Wxapifactory.createwxapi (this, constants.app_id);
Register the APP with the micro-letter Api.registerapp (CONSTANTS.APP_ID);
Calling interface Params p = new Params ();
P.put ("fee", fee);
P.put ("Spbill_create_ip", networkutils.getlocalipaddress (this));
String value = "Commodity title" + title;
try {string title = new String (value.getbytes ("UTF-8"));
P.put ("Body", title);
catch (Unsupportedencodingexception e) {e.printstacktrace ();
} p.put ("UserId", O.getuser (). GetId ()); P.post (C.url. Weixin_pay, New Rehandler () {@Override public void onsuccess (netentity entity) {Wpay = Entity.toob
J (Weixinpay.class);
Payreq req = new Payreq (); Req.appid = Wpay.getappid ();//micro-letter AppId Req.packagevalue = Wpay.getpackagevalue ();//Package Req.extdata = "App D ATA ";
Optional Req.timestamp = Wpay.gettimestamp ();/time Stamp Req.partnerid = Wpay.getpartnerid ();//Merchant Number " Req.prepayid = Wpay.getprepayid ();//Pre-payment order number REQ.NONCESTR = Wpay.getnoncestr ();//random string req.sign = wpay.ge Tsign ()//Background returned signature//local sign again LIST<
namevaluepair> signparams = new linkedlist<namevaluepair> ();
Signparams.add (New Basicnamevaluepair ("AppID", Req.appid));
Signparams.add (New Basicnamevaluepair ("Noncestr", Req.noncestr));
Signparams.add (New Basicnamevaluepair ("package", Req.packagevalue));
Signparams.add (New Basicnamevaluepair ("Partnerid", Req.partnerid));
Signparams.add (New Basicnamevaluepair ("Prepayid", Req.prepayid));
Signparams.add (New Basicnamevaluepair ("timestamp", Req.timestamp));
Req.sign = Genappsign (signparams);
Micro-letter Payment if (api.iswxappinstalled () &&api.iswxappsupportapi ()) {api.sendreq (req);
}else{builder = new Alertdialog.builder (wxpayentryactivity.this);
Builder.setneutralbutton ("Off", new Dialoginterface.onclicklistener () {@Override
public void OnClick (Dialoginterface dialog, int which) {Mdialog.dismiss (); }). Settitle ("Friendly Reminder"). Setmessage ("Please install the micro-letter client");
Mdialog = Builder.create ();
Mdialog.show (); @Override public void OnStart () {} @Override public void OnFailure (String mes
Sage) {}});
Private String genappsign (list<namevaluepair> params) {StringBuilder sb = new StringBuilder ();
for (int i = 0; i < params.size (); i++) {Sb.append (Params.get (i) getName ());
Sb.append (' = ');
Sb.append (Params.get (i). GetValue ());
Sb.append (' & ');
} sb.append ("key=");
Sb.append (Constants.api_key);
This.sb.append ("sign str\n" + sb.tostring () + "\ n");
String appsign = Md5.getmessagedigest (Sb.tostring (). GetBytes ());
LOG.E ("Orion", Appsign);
return appsign;
}
Vi. callback method after success in Wxpayentryactivity class Onresp ()
@Override public
void Onresp (Baseresp resp) {
log.d (TAG, "onpayfinish, Errcode =" + Resp.errcode);
if (resp.gettype () = = constantsapi.command_pay_by_wx) {
if (resp.errcode==-2) {
Toast.maketext (this, "Cancel payment!) ", Toast.length_long). Show ();
if (resp.errcode==-1) {
Toast.maketext (this, "Payment error!) ", Toast.length_long). Show ();
if (resp.errcode==0) {
queryorder ();//query interface calls backend server query succeeded
}
}
Finally finished, must be signed packaging, this is the secret of micro-letter, you forget will jump out-1, hehe.
Finally summarize the payment return-1 of the situation
1. Check the micro-letter background signature, the package name is correct
2. Whether the project is signed and packaged
3. If the previous test has shown-1 of the situation, you must clear the micro-letter clearance data, re-login micro-letter
4. The background server is required to sign the first time, the second signature, if the second signature is not right, then we will sign their own again, my code inside wrote
The above is the whole content of micro-letter payment, I hope to help you learn, but also hope that we support the cloud-dwelling community.