1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| @Controller public class Message { private String apiUrl = "https://sms_developer.zhenzikj.com"; private String appId = ""; private String appSecret = ""; @ResponseBody @GetMapping("/fitness/code") public boolean getCode(@RequestParam("memPhone") String memPhone, HttpSession httpSession){ try { JSONObject json = null; String code = String.valueOf(new Random().nextInt(999999)); ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret); Map<String, Object> params = new HashMap<String, Object>(); params.put("number", "填自己的手机号码"); params.put("templateId", "短信的模板id"); String[] templateParams = new String[2]; templateParams[0] = code; templateParams[1] = "5分钟"; params.put("templateParams", templateParams); String result = client.send(params); System.out.println(result); json = JSONObject.parseObject(result); System.out.println(result); json = new JSONObject(); json.put("memPhone",memPhone); json.put("code",code); json.put("createTime",System.currentTimeMillis()); redisTemplate.expire("verifyCode"+memPhone,1, TimeUnit.MINUTES); return true; } catch (Exception e) { e.printStackTrace(); return @Controller public class Message { private String apiUrl = "https://sms_developer.zhenzikj.com"; private String appId = ""; private String appSecret = ""; @ResponseBody @GetMapping("/fitness/code") public boolean getCode(@RequestParam("memPhone") String memPhone, HttpSession httpSession){ try { JSONObject json = null; String code = String.valueOf(new Random().nextInt(999999)); ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret); Map<String, Object> params = new HashMap<String, Object>(); params.put("number", "填自己的手机号码"); params.put("templateId", "短信的模板id"); String[] templateParams = new String[2]; templateParams[0] = code; templateParams[1] = "5分钟"; params.put("templateParams", templateParams); String result = client.send(params); System.out.println(result); json = JSONObject.parseObject(result); System.out.println(result); json = new JSONObject(); json.put("memPhone",memPhone); json.put("code",code); json.put("createTime",System.currentTimeMillis()); redisTemplate.expire("verifyCode"+memPhone,1, TimeUnit.MINUTES); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }
|