李天标 5 rokov pred
rodič
commit
4f7a1e2f0a

+ 6 - 0
pom.xml

@@ -34,6 +34,12 @@
 	</properties>
 
 	<dependencies>
+		<!-- paytm支付 -->
+		<dependency>
+			<groupId>myjar</groupId>
+			<artifactId>PaytmChecksum</artifactId>
+			<version>1.0</version>
+		</dependency>
 		<!-- Spring Component End -->
 		<dependency>
 			<groupId>org.json</groupId>

+ 148 - 0
src/main/java/com/shawn/web/controller/TWeixinController.java

@@ -5,15 +5,27 @@
 
 package com.shawn.web.controller;
 
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 import com.alibaba.fastjson.JSONObject;
+import com.paytm.pg.merchant.CheckSumServiceHelper;
 import com.shawn.model.entity.*;
 import com.shawn.service.interfac.TAdminServiceInterface;
+import com.shawn.util.JoinpayConstant;
+import com.shawn.util.PushUtils;
 import com.shawn.util.WeChatUtil;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.annotation.Order;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
@@ -25,6 +37,9 @@ import com.shawn.model.param.TWeixinParam;
 import com.shawn.service.interfac.TWeixinServiceInterface;
 
 import lombok.extern.apachecommons.CommonsLog;
+
+import javax.servlet.http.HttpServletRequest;
+
 @CommonsLog
 @RestController
 @RequestMapping("TWeixin")
@@ -43,6 +58,139 @@ public class TWeixinController extends BaseController<TWeixin,TWeixinExample,TWe
 	protected TWeixinExample createNewExample() {
 		return new TWeixinExample();
 	}
+
+    /**
+     * 印度paytm支付
+     * @param
+     * @return
+     */
+    @GetMapping("/paytmpay")
+    public ResponseEntity<?> paytmpay(String orderId,String type ) {
+        /* initialize an object */
+        JSONObject paytmParams = new JSONObject();
+
+        /* body parameters */
+        JSONObject body = new JSONObject();
+        if(type.equals("SMS")){
+            body.put("sendSms", true);
+        }else{
+            body.put("sendEmail", true);
+        }
+        Double amount = 0.10;
+        body.put("amount", amount);
+        /* Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */
+        JSONObject customerContact = new JSONObject();
+        customerContact.put("customerEmail", "520283710@qq.com");
+        customerContact.put("customerMobile", "9910215225");
+        body.put("customerContact", customerContact);
+        body.put("statusCallbackUrl", "https://app.sunzee.com.cn/ShenzeeServer/TWeixin/paytmNotify");
+        body.put("mid", "WorldP64425807474247");
+
+        /* Possible value are "GENERIC", "FIXED", "INVOICE" */
+        body.put("linkType", "LINK_TYPE");
+
+        /* Enter your choice of payment link description here, special characters are not allowed */
+        body.put("linkDescription", "PAYMENT LINK DESCRIPTION");
+
+        /* Enter your choice of payment link name here, special characters and spaces are not allowed */
+        body.put("linkName", "PAYMENTLINKNAME");
+        String result = "";
+/**
+ * Generate checksum by parameters we have in body
+ * You can get Checksum JAR from https://developer.paytm.com/docs/v1/payment-gateway/#code
+ * Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
+ */
+        try { String checksum = CheckSumServiceHelper.getCheckSumServiceHelper().genrateCheckSum("kbzk1DSbJiV_O3p5", body.toString());
+
+        /* head parameters */
+        JSONObject head = new JSONObject();
+        Long startTs = System.currentTimeMillis(); // 当前时间戳
+        /* This will be AES */
+            Long yiu=new Long(9000l);
+            Long cd=new Long(startTs);
+            Long d=cd-yiu;
+//            Long time = startTs-yiu;‬
+        head.put("timestamp", d);
+        head.put("tokenType", "AES");
+
+        /* put generated checksum value here */
+        head.put("signature", checksum);
+
+        /* prepare JSON string for request */
+        paytmParams.put("body", body);
+        paytmParams.put("head", head);
+        String post_data = paytmParams.toString();
+
+        /* for Staging */
+        URL url = new URL("https://securegw-stage.paytm.in/link/create");
+
+        /* for Production */
+// URL url = new URL("https://securegw.paytm.in/link/create);
+
+
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("POST");
+            connection.setRequestProperty("Content-Type", "application/json");
+            connection.setDoOutput(true);
+
+            DataOutputStream requestWriter = new DataOutputStream(connection.getOutputStream());
+            requestWriter.writeBytes(post_data);
+            requestWriter.close();
+            String responseData = "";
+            InputStream is = connection.getInputStream();
+            BufferedReader responseReader = new BufferedReader(new InputStreamReader(is));
+            if ((responseData = responseReader.readLine()) != null) {
+                result=responseData;
+                System.out.append("Response: " + responseData);
+            }
+            // System.out.append("Request: " + post_data);
+            responseReader.close();
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+        return ResponseEntity.status(HttpStatus.OK)
+                .body(new ResultMessage().setCode(true).setData(result).setMessage("success"));
+    }
+    /**
+     * 支付成功回调
+     *
+     * @return
+     */
+    @RequestMapping(value = "/paytmNotify", method = RequestMethod.GET)
+    @ResponseBody
+    public Object refund(HttpServletRequest request) {
+
+//        String r6_Status = request.getParameter("r6_Status");
+        try {String paytmChecksum = null;
+
+        /* Create a TreeMap from the parameters received in POST */
+        TreeMap<String, String> paytmParams = new TreeMap<String, String>();
+        for (Map.Entry<String, String[]> requestParamsEntry : request.getParameterMap().entrySet()) {
+            if ("CHECKSUMHASH".equalsIgnoreCase(requestParamsEntry.getKey())){
+                paytmChecksum = requestParamsEntry.getValue()[0];
+            } else {
+                paytmParams.put(requestParamsEntry.getKey(), requestParamsEntry.getValue()[0]);
+            }
+
+        }
+
+/**
+ * Verify checksum
+ * Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
+ */
+        boolean isValidChecksum = CheckSumServiceHelper.getCheckSumServiceHelper().verifycheckSum("YOUR_KEY_HERE", paytmParams, paytmChecksum);
+        if (isValidChecksum) {
+            System.out.append("Checksum Matched");
+        } else {
+            System.out.append("Checksum Mismatched");
+        }
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+
+        return "success";
+    }
+
 	/**
 	 * 微信登录
 	 * @param