|
@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -36,7 +37,24 @@ public class SDKServiceImpl implements SDKService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseJson<Map<String, String>> getConfigData(String appId, String url) throws Exception {
|
|
|
+ public ResponseJson<Map<String, String>> getConfigData(HttpServletRequest request, String appId, String url) throws Exception {
|
|
|
+ String clientIp = request.getHeader("x-forwarded-for");
|
|
|
+ if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
|
|
+ clientIp = request.getHeader("Proxy-Client-IP");
|
|
|
+ }
|
|
|
+ if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
|
|
+ clientIp = request.getHeader("WL-Proxy-Client-IP");
|
|
|
+ }
|
|
|
+ if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
|
|
+ clientIp = request.getHeader("HTTP_CLIENT_IP");
|
|
|
+ }
|
|
|
+ if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
|
|
+ clientIp = request.getHeader("HTTP_X_FORWARDED_FOR");
|
|
|
+ }
|
|
|
+ if (clientIp == null || clientIp.isEmpty() || "unknown".equalsIgnoreCase(clientIp)) {
|
|
|
+ clientIp = request.getRemoteAddr();
|
|
|
+ }
|
|
|
+ log.info("clientIp--------->" + clientIp);
|
|
|
if (StringUtils.isEmpty(appId)) {
|
|
|
return ResponseJson.error("参数异常,请输入appId", null);
|
|
|
}
|
|
@@ -51,7 +69,7 @@ public class SDKServiceImpl implements SDKService {
|
|
|
// 获取accessToken
|
|
|
String accessToken = null == redisService.get("token:" + appId) ? null : String.valueOf(redisService.get("token:" + appId));
|
|
|
if (StringUtils.isEmpty(accessToken)) {
|
|
|
- Map<String,String> tokenMap = WxUtils.getAccessToken(appId, appSecret);
|
|
|
+ Map<String, String> tokenMap = WxUtils.getAccessToken(appId, appSecret);
|
|
|
if ("-1".equals(tokenMap.get("code"))) {
|
|
|
return ResponseJson.error(tokenMap.get("errmsg"), null);
|
|
|
}
|
|
@@ -60,7 +78,7 @@ public class SDKServiceImpl implements SDKService {
|
|
|
// 获取jsapiTicket
|
|
|
String ticket = null == redisService.get("ticket:" + appId) ? null : String.valueOf(redisService.get("ticket:" + appId));
|
|
|
if (StringUtils.isEmpty(ticket)) {
|
|
|
- Map<String, String> ticketMap = WxUtils.getJsapiTicket(appId,accessToken);
|
|
|
+ Map<String, String> ticketMap = WxUtils.getJsapiTicket(appId, accessToken);
|
|
|
if ("-1".equals(ticketMap.get("code"))) {
|
|
|
return ResponseJson.error(ticketMap.get("errmsg"), null);
|
|
|
}
|
|
@@ -77,7 +95,7 @@ public class SDKServiceImpl implements SDKService {
|
|
|
map.put("ticket", ticket);
|
|
|
map.put("noncestr", noncestr);
|
|
|
map.put("signature", signature);
|
|
|
- log.info("生成签名:>>>>"+signature);
|
|
|
+ log.info("生成签名:>>>>" + signature);
|
|
|
return ResponseJson.success(map);
|
|
|
}
|
|
|
|
|
@@ -85,7 +103,7 @@ public class SDKServiceImpl implements SDKService {
|
|
|
public ResponseJson<Integer> getWxAccountType(String appId) {
|
|
|
Integer wxAccountType = shopMapper.getWxAccountTypeByAppId(appId);
|
|
|
if (null == wxAccountType) {
|
|
|
- return ResponseJson.success(3,"公众号不存在", null);
|
|
|
+ return ResponseJson.success(3, "公众号不存在", null);
|
|
|
}
|
|
|
return ResponseJson.success(wxAccountType);
|
|
|
}
|