| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.gkhy.exam.pay.entity.PayReqData; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.StatusLine; |
| | | import org.apache.http.*; |
| | | import org.apache.http.client.ClientProtocolException; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.HttpResponseException; |
| | |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.util.EntityUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.X509TrustManager; |
| | |
| | | */ |
| | | public class PayUtils { |
| | | |
| | | private final static String appid="ED76A5F1703540BE977D34780B371FEB"; |
| | | |
| | | |
| | | public static ResultVo sendApiPost(PayReqData payReqData) throws IOException { |
| | | |
| | | //正式 |
| | | String proUrl="http://finpt.xjcz.gov.cn/fs-service/fs-pay/invoice.do"; |
| | | String appid="ED76A5F1703540BE977D34780B371FEB"; |
| | | //测试 |
| | | String testUrl= "http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do"; |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | //缴费结果通知 |
| | | public static Map<String,String> receive(JSONObject jsonObject) throws IOException { |
| | | |
| | | Map<String, String> params = new HashMap<>(); |
| | | JSONObject reqdata = new JSONObject(); |
| | | |
| | | Map<String,String> result = (Map<String, String>) jsonObject.get("reqdata"); |
| | | String orderNo = result.get("orderNo"); |
| | | |
| | | //确认是否成功 |
| | | String notarize= affirmPost(orderNo); |
| | | reqdata.put("orderNo",orderNo); |
| | | reqdata.put("status",notarize); |
| | | |
| | | String req = Base64.getEncoder().encodeToString(reqdata.toJSONString().getBytes()); |
| | | String mac = appid+"||"+req; |
| | | mac = DigestUtils.md5Hex(mac.getBytes()); |
| | | params.put("appid",appid); |
| | | params.put("reqdata",req); |
| | | params.put("mac",mac); |
| | | |
| | | return params; |
| | | } |
| | | |
| | | //缴费结果确认查询 |
| | | public static String affirmPost(String orderNo) throws IOException { |
| | | String porUrl="http://finpt.xjcz.gov.cn/fs-service/fs-pay/notifyConfirm.do"; |
| | | String testUrl="http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/notifyConfirm.do"; |
| | | |
| | | HashMap<String, String> param = new HashMap<>(); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("orderNo",orderNo); |
| | | String reqdata = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes()); |
| | | String mac = appid+"||"+reqdata; |
| | | mac=DigestUtils.md5Hex(mac.getBytes()); |
| | | param.put("appid",appid); |
| | | param.put("reqdata",reqdata); |
| | | param.put("mac",mac); |
| | | |
| | | HttpPost httppost = new HttpPost(testUrl); |
| | | httppost.setEntity(assemblyFormEntity(param,"utf-8")); |
| | | HttpClient httpClient = getHttpClient(testUrl); |
| | | HttpResultVo execute = httpClient.execute(httppost, getResponseHandler()); |
| | | String stringContent = execute.getStringContent(); |
| | | ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class); |
| | | System.out.printf("请求结果为:"+resultVo); |
| | | if (resultVo.getRespcode().equals("BUS0000")){ |
| | | return "success"; |
| | | } |
| | | return "fail"; |
| | | } |
| | | |
| | | //缴费结果查询 |
| | | public static JSONObject query(String orderNo) throws IOException { |
| | | String proUrl="http://finpt.xjcz.gov.cn/fs-service/fs-pay/query.do"; |
| | | String testUrl="http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/query.do"; |
| | | |
| | | HashMap<String, String> param = new HashMap<>(); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("orderNo",orderNo); |
| | | String reqdata = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes()); |
| | | String mac = appid+"||"+reqdata; |
| | | mac = DigestUtils.md5Hex(mac.getBytes()); |
| | | param.put("appid",appid); |
| | | param.put("reqdata",reqdata); |
| | | param.put("mac",mac); |
| | | |
| | | HttpPost httppost = new HttpPost(testUrl); |
| | | httppost.setEntity(assemblyFormEntity(param,"utf-8")); |
| | | HttpClient httpClient = getHttpClient(testUrl); |
| | | HttpResultVo execute = httpClient.execute(httppost, getResponseHandler()); |
| | | String stringContent = execute.getStringContent(); |
| | | JSONObject result = JSONObject.parseObject(stringContent); |
| | | System.out.printf("请求结果json为:"+result); |
| | | return result; |
| | | } |
| | | } |