فهرست منبع

国际服支付

lyhzzz 2 سال پیش
والد
کامیت
c2aca37c6d

+ 1 - 0
src/main/java/com/fdkankan/ucenter/controller/LicenseController.java

@@ -8,4 +8,5 @@ import org.springframework.web.bind.annotation.RestController;
 public class LicenseController {
 
 
+
 }

+ 48 - 54
src/main/java/com/fdkankan/ucenter/controller/OrderPaypalController.java

@@ -3,6 +3,7 @@ package com.fdkankan.ucenter.controller;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.ucenter.common.BaseController;
 import com.fdkankan.ucenter.common.Result;
+import com.fdkankan.ucenter.common.ResultData;
 import com.fdkankan.ucenter.pay.factory.PayFactory;
 import com.fdkankan.ucenter.pay.paypal.PayPalDefaultConfig;
 import com.fdkankan.ucenter.pay.paypal.sdk.PaypalService;
@@ -19,7 +20,9 @@ import org.springframework.web.bind.annotation.RequestBody;
 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 javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -44,6 +47,9 @@ public class OrderPaypalController extends BaseController {
 
     @Value("${main.url}")
     private String mainUrl;
+    //正式环境或测试环境
+    @Value("${spring.profiles.active}")
+    private String ev;
 
     /**
      * Paypal付款
@@ -51,13 +57,11 @@ public class OrderPaypalController extends BaseController {
      * orderType    订单类型,0购买相机,1点数重置,2扩容,3商业版,4增值服务,5场景下载
      * spaceId      0表示国内订单,1表示国外订单
      */
+    @ResponseBody
     @RequestMapping(value = "/paypal", method = RequestMethod.POST)
-    public String paypal(@RequestBody PlaceOrderParam order) throws Exception {
+    public Result paypal(@RequestBody PlaceOrderParam order) throws Exception {
         JSONObject jsonObject = payFactory.scanPay("paypal", order);
-        if (jsonObject != null && jsonObject.get("redirect") != null){
-            return "redirect:" + jsonObject.getString("redirect");
-        }
-        return  "redirect:" + mainUrl + config.getFailUrl();
+        return Result.success(jsonObject);
     }
 
     @RequestMapping(value = "/paypalH5", method = RequestMethod.POST)
@@ -71,6 +75,9 @@ public class OrderPaypalController extends BaseController {
 
     /**
      * 支付成功
+     * @param paymentId
+     * @param payerId
+     * @return
      */
     @RequestMapping(value = "/paypal/callback", method = RequestMethod.GET)
     public String successPay(@RequestParam("paymentId") String paymentId,
@@ -108,7 +115,7 @@ public class OrderPaypalController extends BaseController {
      */
     @RequestMapping(value = "/paypal/callbackH5", method = RequestMethod.GET)
     public String successPayH5(@RequestParam("paymentId") String paymentId,
-                             @RequestParam("PayerID") String payerId) {
+                               @RequestParam("PayerID") String payerId) {
         try {
             log.warn("=====paypal支付回调=====\npaymentId:"+paymentId+"\npayerId:"+payerId);
             Payment payment = paypalService.executePayment(paymentId, payerId);
@@ -154,6 +161,7 @@ public class OrderPaypalController extends BaseController {
     /**
      *  Paypal的INP异步通知服务器, 需要修改Paypal官网即时付款通知IPN通告URL
      */
+    @ResponseBody
     @RequestMapping(value = "/paypal/notify", method = RequestMethod.POST)
     public void callback() {
         Enumeration en = request.getParameterNames();
@@ -193,60 +201,46 @@ public class OrderPaypalController extends BaseController {
         log.info("custom:"+custom);
         String orderSn = custom.split("_")[0];
         try {
-            //构建post请求给paypal,将信息 POST 回给 PayPal 进行验证
-            //String url = "https://www.sandbox.paypal.com/cgi-bin/webscr";//沙箱环境
-            //String url = new URL("https://www.paypal.com/cgi-bin/webscr");//正式环境
-            String url = "https://www.paypal.com/cgi-bin/webscr";//正式环境
-            //http框架用的是okhttp,okhttp也依赖okio的jar包
-            OkHttpClient client = new OkHttpClient();
-            okhttp3.RequestBody body = okhttp3.RequestBody.create(MediaType.parse("text/plain; charset=utf-8"), str);
-            Request req = new Request.Builder().post(body).url(url).build();
-            client.newCall(req).enqueue(new Callback() {
-                @Override
-                public void onFailure(Call arg0, IOException arg1) {
-                    log.error("构建post请求给paypal时候发生了错误:" + custom);
-                }
-                @Override
-                public void onResponse(Call arg0, Response arg1) throws IOException {
-                    String str = arg1.body().string();
-                    //验证通过
-                    if ("VERIFIED".equals(str)) {
-//	                    StringBuilder sb = new StringBuilder();
-//	                    sb.append("付款成功参数:itemName=").append(itemName).append(",itemNumber=").append(itemNumber).
-//	                    append("付款成功参数:paymentStatus=").append(paymentStatus).append(",paymentDate=").append(paymentDate).
-//	                    append("付款成功参数:paymentAmount=").append(paymentAmount).append(",paymentCurrency=").append(paymentCurrency).
-//	                    append("付款成功参数:txnId=").append(txnId).append(",receiverEmail=").append(receiverEmail).
-//	                    append("付款成功参数:payerEmail=").append(payerEmail);
-//	                    log.info(sb.toString());
-
-                        //1.确认“payment_status”为“Completed”,因为系统也会为其他结果(如“Pending”或“Failed”)发送 IPN。
-                        //2.检查“txn_id”是否未重复,以防止欺诈者重复使用旧的已完成的交易
-                        //3.验证“receiver_email”是已在您的PayPal账户中注册的电子邮件地址,以防止将付款发送到欺诈者的账户
-                        if ("Completed".equals(paymentStatus)) {
-                            //根据自己业务进行处理(修改订单状态,支付时间等等操作)
-                            try {
-                                log.info("paypal支付成功回调");
-                                //表示续费,有消费记录id
-                                if(custom.split("_").length > 2 && custom.split("_")[2].matches("^-?[0-9]+")){
-                                    orderStrategyFactory.doHandler(custom.split("_")[0] + "_" + custom.split("_")[2], txnId, payerEmail, custom.split("_")[1], 2);
-                                }else {
-                                    orderStrategyFactory.doHandler(orderSn, txnId, payerEmail, custom.split("_")[1], 2);
-                                }
-                            } catch (Exception e) {
-                                log.error("paypal支付回调异常,errorMsg:{}", e.getMessage());
-                            }
-                        }
-                    } else if ("VERIFIED".equals(str)) {
-                        log.error("付款失败回调VERIFIED,订单号=" + orderSn);
+
+
+            if ("Completed".equals(paymentStatus)) {
+                //根据自己业务进行处理(修改订单状态,支付时间等等操作)
+                try {
+                    log.info("paypal支付成功回调");
+                    //表示续费,有消费记录id
+                    if (custom.split("_").length > 2 && custom.split("_")[2].matches("^-?[0-9]+")) {
+                        orderStrategyFactory.doHandler(custom.split("_")[0] + "_" + custom.split("_")[2], txnId, payerEmail, custom.split("_")[1], 2);
                     } else {
-                        log.error("付款无效回调VERIFIED,订单号=" + orderSn);
+                        orderStrategyFactory.doHandler(orderSn, txnId, payerEmail, custom.split("_")[1], 2);
                     }
+                } catch (Exception e) {
+                    log.error("paypal支付回调异常,errorMsg:{}", e.getMessage());
                 }
-            });
-        } catch (Exception e) {
+            }
+        }catch (Exception e) {
             log.error("paypal支付回调异常,errorMsg:{}", e.getMessage());
         }
+
     }
 
+    @RequestMapping(value = "/paypalresult", method = RequestMethod.GET)
+    @org.springframework.web.bind.annotation.ResponseBody
+    public Result paypalresult(HttpServletRequest request) throws Exception {
+        if(!ev.equals("test-eur")){
+            return  Result.failure("正式环境不允许调用!");
+        }
+
+        String orderSn = request.getParameter("orderSn");
+        String txnId = request.getParameter("txnId");
+        String payerEmail = request.getParameter("payer_email");//付款人email
+        String type = request.getParameter("type");//付款人email
+
+
+        //download  ,increment
+
+        orderStrategyFactory.doHandler(orderSn, txnId, payerEmail, type, 2);
+        return  Result.success();
+
+    }
 
 }

+ 2 - 2
src/main/resources/mapper/ucenter/SceneProMapper.xml

@@ -103,8 +103,8 @@
         <if test="param.numList == null and param.userId != null ">
            and p.user_id =#{param.userId}
         </if>
-        <if test="param.camaraId != null ">
-           and p.camera_id =#{param.camaraId}
+        <if test="param.cameraId != null ">
+           and p.camera_id =#{param.cameraId}
         </if>
     </sql>