Micro-Credit Payment Java version of the query order _java

Source: Internet
Author: User

The example of this article for everyone to share the micro-letter Payment order query interface for your reference, the specific contents are as follows

1. Introduction to the interface




2. Code implementation

Package com.zhrd.bussinss.platform.controller.shop;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.security.KeyStore;
Import Java.text.SimpleDateFormat;

Import Java.util.Date;
Import Javax.net.ssl.SSLContext;
Import Javax.servlet.http.HttpServletRequest;

Import Javax.servlet.http.HttpServletResponse;

Import Net.sf.json.JSONObject;
Import org.apache.http.HttpEntity;
Import Org.apache.http.client.methods.CloseableHttpResponse;
Import Org.apache.http.client.methods.HttpPost;
Import Org.apache.http.conn.ssl.SSLConnectionSocketFactory;
Import org.apache.http.conn.ssl.SSLContexts;
Import org.apache.http.entity.StringEntity;
Import org.apache.http.impl.client.CloseableHttpClient;
Import org.apache.http.impl.client.HttpClients;
Import org.dom4j.Document;
Import org.dom4j.Element;
Import Org.dom4j.io.SAXReader;
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.stereotype.Controller; Import Org.springframework.web.bind.annotation.Requestmapping;
Import Org.springframework.web.bind.annotation.RequestMethod;
Import Org.springframework.web.bind.annotation.RequestParam;

Import Org.springframework.web.bind.annotation.ResponseBody;
Import Com.zhrd.bussinss.platform.service.WeiXinPayService;
Import Com.zhrd.bussinss.platform.utils.CustomizedPropertyPlaceholderConfigurer;

Import Com.zhrd.bussinss.platform.weixinPayUtils.ClientCustomSSL; @Controller @RequestMapping ("/shop/weixinpayordersearch") public class Weixinpayordersearchcontroller {@Autowired W
 
 
 
 Eixinpayservice Weixinpayservice; /** * Micro-credit Expense order status query * @param request * @param response * @return * * * @RequestMapping (value= "/init", Method=requestmethod.
 
 Get) public String init (httpservletrequest request,httpservletresponse response) {return "Weixinpayordersearch"; /** * Micro-credit Expense order status query * @param request * @param response * @return * * @RequestMapping (value= "/getweixinpayorder", Me Thod=requestmethod.post) @ResponseBody public Object GETWEIXINPAyorder (httpservletrequest request,httpservletresponse response, @RequestParam (required=false) String TransactionID
  , @RequestParam (required=false) String Outtradeno) {try{KeyStore KeyStore = keystore.getinstance ("PKCS12"); FileInputStream instream = new FileInputStream (New File (Customizedpropertyplaceholderconfigurer.getcontextproperty (
  "Wx.cert"). toString ());
  try {keystore.load (instream, see Mail). ToCharArray ());
  }finally {instream.close ();
   }//Trust own CA and all self-signed certs sslcontext sslcontext = Sslcontexts.custom (). Loadkeymaterial (KeyStore,
  "10061401". ToCharArray ()). build (); Allow TLSV1 protocol only sslconnectionsocketfactory SSLSF = new Sslconnectionsocketfactory (Sslcontext, New Strin
  G[] {"TLSV1"}, NULL, sslconnectionsocketfactory.allow_all_hostname_verifier);
  Closeablehttpclient httpclient = Httpclients.custom (). Setsslsocketfactory (SSLSF). build (); HttpGet HttpGet = new//HttpGet ("Https://api.mch.weixin.qq.com/secApi/pay/refund ");
  HttpPost HttpPost = new HttpPost ("Https://api.mch.weixin.qq.com/pay/orderquery");
  Date dt = new Date ();
  SimpleDateFormat SDF = new SimpleDateFormat ("Yyyymmddhhmmss"); String noncestr = sdf.format (dt). toString (); <pre name= "code" class= "Java" > String XML = Clientcustomssl.searchnat Ivepackage (Transactionid.trim (), "", noncestr)//Here is the micro-client ID (both local ID and server-side ID can be queried) try {stringentity se = new Stringentity (
  
  XML);

  Httppost.setentity (SE);

  SYSTEM.OUT.PRINTLN ("Executing request" + httppost.getrequestline ());
  Closeablehttpresponse responseentry = Httpclient.execute (HttpPost);

   try {httpentity entity = responseentry.getentity ();
   System.out.println ("----------------------------------------");
   System.out.println (Responseentry.getstatusline ());
   if (entity!= null) {System.out.println ("Response Content Length:" + entity.getcontentlength ()); /*bufferedreader BufferedReader = new BufferedReader (New InputStreamReader (entity.getContent ()));
   String text;
   while (Text = Bufferedreader.readline ())!= null) {System.out.println ("=======" +text);
   }*/Saxreader saxreader = new Saxreader ();
   Document document = Saxreader.read (Entity.getcontent ());
   Element Rootelt = Document.getrootelement ();
   SYSTEM.OUT.PRINTLN ("root node:" + Rootelt.getname ());
   System.out.println ("= =" +rootelt.elementtext ("Result_code"));
   System.out.println ("= =" +rootelt.elementtext ("return_msg"));
   String ResultCode = Rootelt.elementtext ("Result_code");
   String ReturnCode = Rootelt.elementtext ("Return_code");
   Jsonobject result = new Jsonobject ();
   System.out.println ("resultcode=====" +resultcode);
   System.out.println ("returncode=====" +returncode);
   System.out.println ("trade_state=====" +rootelt.elementtext ("Trade_state"));
   System.out.println ("transaction_id=====" +rootelt.elementtext ("transaction_id"));
   System.out.println ("out_trade_no=====" + rootelt.elementtext ("Out_trade_no")); System.out.println ("total_fee=====" +rootelt.elementtext ("Total_fee")); if (ResultCode!= null && resultcode.equals ("SUCCESS") && returncode.equals ("SUCCESS")) {Result.put ("t
    Radestate ", Rootelt.elementtext (" trade_state "));
    Result.put ("TransactionID", Rootelt.elementtext ("transaction_id"));
    Result.put ("Outtradeno", Rootelt.elementtext ("Out_trade_no"));
    Result.put ("Totalfee", Rootelt.elementtext ("Total_fee"));
    Result.put ("Status", "Success");
   Result.put ("MSG", "success");
    }else if (returncode.equals ("SUCCESS")) {result.put ("Errorcheck", "Errcode");
    Result.put ("Status", "false");
   Result.put ("ErrorMsg", Rootelt.elementtext ("Err_code_des"));
    }else{result.put ("Errorcheck", "errmsg");
    Result.put ("Status", "false");
   Result.put ("ErrorMsg", Rootelt.elementtext ("return_msg"));

   return result;
  }//Entityutils.consume (entity);
  finally {responseentry.close ();
  finally {httpclient.close (); }}catch (excEption e) {e.printstacktrace ();
  Jsonobject result = new Jsonobject ();
  Result.put ("Status", "error");
  Result.put ("msg", E.getmessage ());
 return result;
 
 
 Return "";


 }

}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.