RequestHandler RequestHandler = new RequestHandler (Super.getrequest (), Super.getresponse ());
Get token//valid within two hours, regain after two hours
Token = Requesthandler.gettoken ();
Update token to Application
Requesthandler.gettokenreal ();
SYSTEM.OUT.PRINTLN ("micro-credit payment acquisition token=======================:" +token);
RequestHandler initialization
Requesthandler.init ();
Requesthandler.init (Appid,appsecret, Appkey,partnerkey, key); Code: Local System Generation Order Set up Package order parameters
sortedmap<string, string> packageparams = new treemap<string, string> ();
Packageparams.put ("Bank_type", "WX"); Payment type
Packageparams.put ("Body", "xxxx"); Product Description
Packageparams.put ("Fee_type", "1"); Currency of bank
Packageparams.put ("Input_charset", "UTF-8"); Character
Packageparams.put ("Notify_url", "Http://xxxx.com/xxxx/wxcallback"); The notification address here uses an extranet address test to see if Port 80 is open.
Packageparams.put ("Out_trade_no", no); Merchant Order Number
Packageparams.put ("partner", Partenerid); Set up merchant numbers
Packageparams.put ("Spbill_create_ip", Super.getrequest (). Getremotehost ()); Order-generated machine IP, which refers to the user's browser-side IP
Packageparams.put ("Total_fee", String.valueof (Rstotal)); Total amount of merchandise to be divided into units
Set up payment parameters
sortedmap<string, string> signparams = new treemap<string, string> ();
Signparams.put ("AppID", AppID);
Signparams.put ("Noncestr", noncestr);
Signparams.put ("Traceid", Propertiesutils.getorderno ());
Signparams.put ("timestamp", timestamp);
Signparams.put ("package", packagevalue);
Signparams.put ("Appkey", This.appkey);
Generate payment signatures, to use the original value of Urlencoder SHA1 algorithm!
String sign = "";
try {
Sign = sha1util.createsha1sign (signparams);
catch (Exception e) {
E.printstacktrace ();
}
Increase extra parameters for non-participating signatures
Signparams.put ("Sign_method", "SHA1");
Signparams.put ("App_signature", sign);
API Payment LCL End------------------------------------
Get Prepayid
String Prepayid = Requesthandler.sendprepay (signparams);
System.out.println ("Prepayid:" + Prepayid); Code: Generate Prepaid Quick order complete Generate prepaid Quick order completion and return the parameters required for Android,ios to drop the micro-letter.
sortedmap<string, string> payparams = new treemap<string, string> ();
Payparams.put ("AppID", AppID);
Payparams.put ("Noncestr", noncestr);
Payparams.put ("Package", "Sign=wxpay");
Payparams.put ("Partnerid", Partenerid);
Payparams.put ("Prepayid", Prepayid);
Payparams.put ("Appkey", This.appkey);
In addition to the 1000 is because of the parameter length limit.
int time = (int) (System.currenttimemillis ()/1000);
Payparams.put ("timestamp", string.valueof (time));
System.out.println ("timestamp:" + time);
Signature
String paysign = "";
try {
Paysign = Sha1util.createsha1sign (payparams);
catch (Exception e) {
E.printstacktrace ();
}
Payparams.put ("sign", paysign);
Spell-JSON data returned to the client
Basicdbobject backobject = new Basicdbobject ();
Backobject.put ("AppID", AppID);
Backobject.put ("Noncestr", Payparams.get ("Noncestr"));
Backobject.put ("Package", "Sign=wxpay");
Backobject.put ("Partnerid", Payparams.get ("Partnerid"));
Backobject.put ("Prepayid", Payparams.get ("Prepayid"));
Backobject.put ("Appkey", This.appkey);
Backobject.put ("timestamp", Payparams.get ("timestamp"));
Backobject.put ("Sign", Payparams.get ("sign"));
String backstr = dataobject.tostring ();
System.out.println ("Backstr:" + backstr);
return backstr; So far, the prepayment order has been generated and returned to the client, waiting for the micro-server to notify the address of the notify_url that generated the prepayment order ResponseHandler Reshandler = new ResponseHandler (request, response);
Reshandler.setkey (Partnerkey);
Create a Request object
RequestHandler queryreq = new RequestHandler (request, response);
Queryreq.init ();
if (reshandler.istenpaysign () = = True) {
Merchant Order Number
String out_trade_no = Reshandler.getparameter ("Out_trade_no");
System.out.println ("Out_trade_no:" + out_trade_no);
Tenpay Order Number
String transaction_id = Reshandler.getparameter ("transaction_id");
System.out.println ("transaction_id:" + transaction_id);
Amount to be divided into units
String Total_fee = Reshandler.getparameter ("Total_fee"); If there is a discount coupon used, the discount has a value, total_fee+discount= the original request Total_fee
String Discount = reshandler.getparameter ("discount");
Payment Results
String trade_state = Reshandler.getparameter ("Trade_state");
Judging signatures and results
if ("0". Equals (Trade_state)) {
//------------------------------
Instant to account processing business start
//------------------------------
SYSTEM.OUT.PRINTLN ("----------------Business logic Execution-----------------");
--Write a program based on your business logic (the above code is for reference only)--
SYSTEM.OUT.PRINTLN ("----------------business logic execution completed-----------------");
SYSTEM.OUT.PRINTLN ("Success"); Please do not modify or delete
SYSTEM.OUT.PRINTLN ("Instant to account payment success");
Send a success message to the Tenpay system and the Tenpay system will not follow up after receiving this result
RESHANDLER.SENDTOCFT ("Success");
Return success to the micro-mail server otherwise 30 minutes notice 8 times
Return "Success";
}else{
System.out.println ("Notify Signature verification failure");
RESHANDLER.SENDTOCFT ("fail");
Response.setcharacterencoding ("Utf-8");
}
}else {
System.out.println ("Fail-md5 failed");
} |