Browse Source

新增支付通道

Yangzw 8 months ago
parent
commit
148ad33870

+ 13 - 2
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/controller/app/fuyouorder/NewPayOrderController.java

@@ -6,6 +6,7 @@ import cn.newfeifan.mall.module.pay.fuiou.reqvo.SubmitOrderRequestVO;
 import cn.newfeifan.mall.module.pay.fuiou.respVO.FuYouPaymentResponseVO;
 import cn.newfeifan.mall.module.pay.fuiou.util.FuiouHttpPoster;
 import cn.newfeifan.mall.module.pay.fuiou.util.MD5;
+import cn.newfeifan.mall.module.pay.fuiou.util.Test;
 import cn.newfeifan.mall.module.pay.service.fuyouorder.FuYouPayOrderService;
 import com.alibaba.fastjson.JSON;
 import io.swagger.v3.oas.annotations.Operation;
@@ -55,8 +56,6 @@ public class NewPayOrderController {
     @PostMapping("/test2")
     @Operation(summary = "test2")
     public CommonResult<String> test2() {
-        FuiouHttpPoster http = new FuiouHttpPoster();
-        http.setUrl("//");
         String s = MD5.MD5Encode("123");
         return success("success");
     }
@@ -72,6 +71,18 @@ public class NewPayOrderController {
         }
         return success("success");
     }
+    @PostMapping("/test4")
+    @Operation(summary = "test4")
+    public CommonResult<String> test4() {
+        Test http = new Test();
+        http.setUrl("//");
+//        try {
+//            String res = http.newPost(JSON.toJSONString(""));
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
+        return success("success");
+    }
 
     @PostMapping("/notify")
     @Operation(summary = "富友支付订单回调")

+ 149 - 0
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/fuiou/util/Test.java

@@ -0,0 +1,149 @@
+/**
+ *
+ */
+package cn.newfeifan.mall.module.pay.fuiou.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+import lombok.Setter;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+
+
+/**
+ * @author Administrator
+ *
+ */
+@Setter
+public class Test {
+
+    public Test() {
+    }
+
+    private String url;
+
+    private String charset;
+
+    public Test(String url, String charset) {
+        super();
+        this.url = url;
+        this.charset = charset;
+    }
+
+    public Test(String url) {
+        super();
+        this.url = url;
+        this.charset = Charset.defaultCharset().name();
+    }
+
+
+
+//    public String newPost(final String body) throws Exception {
+//        return post(new PostMethodCallback() {
+//
+//            @Override
+//            public void doInPostMethod(PostMethod postMethod) {
+//
+//                try {
+//                    postMethod.setRequestEntity(new StringRequestEntity(body,"application/json","UTF-8"));
+//                } catch (UnsupportedEncodingException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//        });
+//    }
+
+
+
+    /**
+     * 使用http协议发送xmltext到url
+     //	 *
+     //	 * @param url
+     //	 *            将要发送的地址
+     //	 * @param xmltext
+     //	 *            将要发送的内容
+     //	 * @return http返回码
+     //	 * @throws LoanException
+     //	 * @throws Exception
+     */
+//    private String post(PostMethodCallback callback) throws Exception {
+//        PostMethod xmlpost = null;
+//        HttpClient httpclient = new HttpClient();
+//        try {
+//            // https设置
+//            if (url.indexOf("https://") != -1) {
+//                // 创建SSL连接
+//                @SuppressWarnings("deprecation")
+//                Protocol myhttps = new Protocol("https",
+//                        new MySSLSocketFactory(), 443);
+//                Protocol.registerProtocol("https", myhttps);
+//            }
+//            httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(60 * 1000);
+//            httpclient.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
+//            xmlpost = new PostMethod(url);
+//            httpclient.getParams().setParameter(
+//                    HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
+//            httpclient.getParams().setContentCharset(charset);
+//            // xmlpost.setRequestHeader("content-type", "text/xml; charset=" +
+//            // charset);
+//
+//            // 内部回调,发送数据,设置参数用
+//            callback.doInPostMethod(xmlpost);
+//            // 执行请求
+//            httpclient.executeMethod(xmlpost);
+//
+//            // 获取返回信息
+//            InputStream ips = xmlpost.getResponseBodyAsStream();
+//            List<Byte> byteList = new ArrayList<Byte>();
+//
+//            int is = 0;
+//            while ((is = ips.read()) != -1)
+//                byteList.add((byte) is);
+//
+//            byte[] allb = new byte[byteList.size()];
+//            for (int j = 0; j < byteList.size(); j++)
+//                allb[j] = byteList.get(j);
+//            String responseString = new String(allb, charset);
+//            // LogWriter.debug(this, "HTTP返回码=" + responseStatCode);
+//            System.out.println("应答数据=" + responseString);
+//
+//            if (url.indexOf("https://") != -1)
+//                Protocol.unregisterProtocol("https");
+//            return responseString;
+//        } catch (IOException ex2) {
+//            ex2.printStackTrace();
+//            System.out.println("报文发送到[" + url + "]失败:" + ex2.getMessage());
+//            throw new Exception("报文发送异常");
+//        } catch (Exception ex) {
+//            ex.printStackTrace();
+//            System.out.println("报文发送到[" + url + "]失败:" + ex.getMessage());
+//            throw new Exception("报文发送异常");
+//        } finally {
+//            try {
+//                if(xmlpost != null)
+//                    xmlpost.releaseConnection();
+//                if(httpclient != null)
+//                    httpclient.getHttpConnectionManager().closeIdleConnections(0);
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
+//    }
+
+    /**
+     * PostMethod回调处理
+     *
+     */
+//    public interface PostMethodCallback {
+//        public void doInPostMethod(PostMethod postMethod);
+//    }
+
+}