|
@@ -0,0 +1,106 @@
|
|
|
+package com.tzld.piaoquan.risk.control.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.tzld.piaoquan.risk.control.common.base.CommonResponse;
|
|
|
+import com.tzld.piaoquan.risk.control.config.QywxConfig;
|
|
|
+import com.tzld.piaoquan.risk.control.model.qywx.QwCommonResModel;
|
|
|
+import com.tzld.piaoquan.risk.control.model.qywx.QwInitResponseModel;
|
|
|
+import com.tzld.piaoquan.risk.control.model.qywx.QwLoginCheckCode;
|
|
|
+import com.tzld.piaoquan.risk.control.model.qywx.QwLoginQRCodeModel;
|
|
|
+import com.tzld.piaoquan.risk.control.service.QwLoginService;
|
|
|
+import com.tzld.piaoquan.risk.control.service.qywx.Constant;
|
|
|
+import com.tzld.piaoquan.risk.control.util.HttpClientUtil;
|
|
|
+import com.tzld.piaoquan.risk.control.util.HttpPoolClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class QwLoginServiceImpl implements QwLoginService {
|
|
|
+ private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(10000, 10000, 2000, 5000, 5, 10000);
|
|
|
+ @Autowired
|
|
|
+ private QywxConfig qywxConfig; // 注入配置类
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(QwLoginServiceImpl.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public QwCommonResModel<QwLoginQRCodeModel> getLoginQRCode(String phoneNumber) {
|
|
|
+ String uuid = initUUID(phoneNumber);
|
|
|
+ LOGGER.info("getLoginQRCode,uuid: {}", uuid);
|
|
|
+ System.out.println("getLoginQRCode,uuid: " + uuid);
|
|
|
+ setCallback(uuid);
|
|
|
+ if (uuid != null) {
|
|
|
+ String url = qywxConfig.getDomain() + qywxConfig.getPath("login-qrcode");
|
|
|
+ Map<String, Object> requestBody = new HashMap<>();
|
|
|
+ requestBody.put("uuid", uuid);
|
|
|
+ String params = JSON.toJSONString(requestBody);
|
|
|
+ Optional<String> response = httpPoolClientDefault.postJson(url, params);
|
|
|
+ if (response.isPresent()) {
|
|
|
+ QwCommonResModel<QwLoginQRCodeModel> qrCodeModel = QwCommonResModel.parseResponse(response.get(), QwLoginQRCodeModel.class);
|
|
|
+ return qrCodeModel;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int checkQRCode(QwLoginCheckCode checkQrcode) {
|
|
|
+ String url = qywxConfig.getDomain() + qywxConfig.getPath("login-checkcode");
|
|
|
+ Optional<String> response = httpPoolClientDefault.postJson(url, JSON.toJSONString(checkQrcode));
|
|
|
+ System.out.println("checkQRCode,response: " + response);
|
|
|
+ if (response.isPresent()) {
|
|
|
+ QwCommonResModel<Object> model = QwCommonResModel.parseResponse(response.get(), Object.class);
|
|
|
+ return model.getErrcode();
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String initUUID(String phoneNumber){
|
|
|
+ Map<String, Object> requestBody = new HashMap<>();
|
|
|
+ requestBody.put("vid", ""); // Add vid if available,二次登录使用上一次结果
|
|
|
+ requestBody.put("ip", ""); // Add proxy IP if available
|
|
|
+ requestBody.put("port", ""); // Add proxy port if available
|
|
|
+ requestBody.put("proxyType", ""); // Add proxy type if available
|
|
|
+ requestBody.put("userName", ""); // Add proxy username if available
|
|
|
+ requestBody.put("passward", ""); // Add proxy password if available
|
|
|
+ requestBody.put("proxySituation", 0); // Default value
|
|
|
+ requestBody.put("deverType", "ipad"); // Default device type
|
|
|
+ // Convert the request body to JSON string
|
|
|
+ String params = JSON.toJSONString(requestBody);
|
|
|
+ String url = qywxConfig.getDomain() + qywxConfig.getPath("init-uuid");
|
|
|
+ Optional<String> response = httpPoolClientDefault.postJson(url, params);
|
|
|
+ // 直接解析 JSON
|
|
|
+ if (response.isPresent()) {
|
|
|
+ System.out.println("init,response: " + response);
|
|
|
+ QwCommonResModel<QwInitResponseModel> initModel = QwCommonResModel.parseResponse(response.get(), QwInitResponseModel.class);
|
|
|
+ return initModel.getData().getUuid();
|
|
|
+ } else {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setCallback(String uuid) {
|
|
|
+ String callbackUrl = Constant.TEST_CALLBACK_URL; // Replace with your actual callback URL
|
|
|
+ String url = qywxConfig.getDomain() + qywxConfig.getPath("add-qwcallback");
|
|
|
+ Map<String, Object> requestBody = new HashMap<>();
|
|
|
+ requestBody.put("uuid", uuid);
|
|
|
+ requestBody.put("url", callbackUrl); // Add callback URL if available
|
|
|
+ String params = JSON.toJSONString(requestBody);
|
|
|
+ Optional<String> response = httpPoolClientDefault.postJson(url, params);
|
|
|
+ if (response.isPresent()) {
|
|
|
+ QwCommonResModel<Object> model = QwCommonResModel.parseResponse(response.get(), Object.class);
|
|
|
+ System.out.println("setCallback success,response: " + response);
|
|
|
+ if (model.getErrcode() == 0) {
|
|
|
+ System.out.println("Callback set successfully");
|
|
|
+ } else {
|
|
|
+ System.out.println("Failed to set callback: " + model.getErrmsg());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("Failed to set callback: No response");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|