提交 edf43d1f authored 作者: 000516's avatar 000516 提交者: Coding

使用快速获取手机号次数(今日)

Merge Request: 使用快速获取手机号次数(今日) Created By: @李秋林 Accepted By: @李秋林 URL: https://g-pkkp8204.coding.net/p/promotion/d/promotion-service/git/merge/257?initial=true
package com.wangxiaolu.promotion.controller.user.tem; package com.wangxiaolu.promotion.controller.user.tem;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.exception.FlowException;
import com.wangxiaolu.promotion.result.basedata.R; import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.utils.TencentUtils; import com.wangxiaolu.promotion.utils.TencentUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Map; import java.util.Objects;
/** /**
* @author : liqiulin * @author : liqiulin
...@@ -15,28 +21,64 @@ import java.util.Map; ...@@ -15,28 +21,64 @@ import java.util.Map;
* @describe : * @describe :
*/ */
@RestController @RestController
@RequestMapping("/wechat/miniapp/") @RequestMapping("/wechat/miniapp")
public class MiappInfoController { public class MiappInfoController {
@Autowired @Autowired
private TencentUtils tencentUtils; private TencentUtils tencentUtils;
@Autowired
private RedisCache redisCache;
/** /**
* 获取小程序信息 * 获取小程序信息 access_token
* @return
*/ */
@GetMapping("/wxtoken") // @GetMapping("/wxtoken")
public R getCX() { // public R getCX() {
return R.success(tencentUtils.getMiniappToken()); // return R.success(tencentUtils.getMiniappToken());
} // }
@GetMapping("/phone") @GetMapping("/phone")
public R getPhone(String accessToken,String code){ public R getPhone(String openId, String code) {
return R.success(tencentUtils.getUserPhoneByAccessToken(accessToken,code)); // 检测当前openId获取phone的次数
checkPhone(openId);
JSONObject tokenJson = tencentUtils.getMiniappToken();
JSONObject phoneJson = tencentUtils.getUserPhoneByAccessToken(tokenJson.getString("access_token"), code);
return R.success(phoneJson);
} }
@GetMapping("/openid") @GetMapping("/openid")
public R getOpenid(String jsCode){ public R getOpenid(String jsCode) {
return R.success(tencentUtils.getOpenid(jsCode)); return R.success(tencentUtils.getOpenid(jsCode));
} }
/**
* 快速获取手机号的次数
* @return count
*/
@GetMapping("/logincount")
public R getLoginPhoneCount(String openId){
String key = RedisKeys.TemporaryKeys.TEMPORARY_LOGIN_OPENID_COUNT.getKey();
key = key + DateUtil.today() + "_" + openId;
return R.success(redisCache.get(key));
}
private synchronized void checkPhone(String openId) {
String key = RedisKeys.TemporaryKeys.TEMPORARY_LOGIN_OPENID_COUNT.getKey();
key = key + DateUtil.today() + "_" + openId;
String countStr = redisCache.get(key);
if (Objects.isNull(countStr)) {
countStr = String.valueOf(1);
redisCache.addToMinute(key, countStr, 1440);
return;
}
Integer count = Integer.valueOf(countStr);
count +=1;
if (count >= 6) {
throw new FlowException(RCode.LOGIN_PHONE_COUNT_MUCH);
}
countStr = String.valueOf(count);
redisCache.addToMinute(key, countStr, 1440);
}
} }
...@@ -13,14 +13,10 @@ import com.tencentcloudapi.sms.v20210111.models.SendStatus; ...@@ -13,14 +13,10 @@ import com.tencentcloudapi.sms.v20210111.models.SendStatus;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.groovy.util.Maps;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Map;
/** /**
* @author : liqiulin * @author : liqiulin
* @date : 2024-04-15 15 * @date : 2024-04-15 15
...@@ -60,9 +56,6 @@ public class TencentUtils { ...@@ -60,9 +56,6 @@ public class TencentUtils {
@Value("${wx.cx_miniapp.app_secret}") @Value("${wx.cx_miniapp.app_secret}")
private String xltAppSecret; private String xltAppSecret;
public Map<String,String> getCX() {
return Maps.of("appId", xltAppId, "appSecret", xltAppSecret);
}
/** /**
* 给指定手机号发送验证码 * 给指定手机号发送验证码
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论