|
@@ -1,6 +1,6 @@
|
|
|
package com.zskk.service;
|
|
|
|
|
|
-import javax.sql.DataSource;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -12,11 +12,17 @@ import com.aliyuncs.exceptions.ClientException;
|
|
|
import com.aliyuncs.exceptions.ServerException;
|
|
|
import com.aliyuncs.http.MethodType;
|
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
|
-import com.jfinal.kit.PropKit;
|
|
|
+import com.jfinal.kit.StrKit;
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
import com.jfinal.plugin.druid.DruidPlugin;
|
|
|
+import com.jfinal.plugin.redis.Redis;
|
|
|
+import com.zskk.controller.bean.DoctorBean;
|
|
|
+import com.zskk.controller.bean.LoginBean;
|
|
|
import com.zskk.model.Doctors;
|
|
|
+import com.zskk.model.DoctorsWechat;
|
|
|
+import com.zskk.model.Institution;
|
|
|
import com.zskk.model._MappingKit;
|
|
|
+import com.zskk.util.ErrorConstant;
|
|
|
|
|
|
public class SmsService {
|
|
|
|
|
@@ -29,36 +35,84 @@ public class SmsService {
|
|
|
arp.start();
|
|
|
}
|
|
|
|
|
|
- public static void sendSmsCode(String phone) {
|
|
|
+ public Boolean sendSmsCode(String phone) {
|
|
|
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "LTAImzRGKfWaL7Vi", "GjWdd2cdHtbQkhhnhSxNbw0QChKD98");
|
|
|
IAcsClient client = new DefaultAcsClient(profile);
|
|
|
-
|
|
|
+ String code = creatRandomCode();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("code", code);
|
|
|
CommonRequest request = new CommonRequest();
|
|
|
request.setMethod(MethodType.POST);
|
|
|
request.setDomain("dysmsapi.aliyuncs.com");
|
|
|
request.setVersion("2017-05-25");
|
|
|
request.setAction("SendSms");
|
|
|
request.putQueryParameter("RegionId", "cn-beijing");
|
|
|
- request.putQueryParameter("PhoneNumbers", "18141913818");
|
|
|
+ request.putQueryParameter("PhoneNumbers", phone);
|
|
|
request.putQueryParameter("SignName", "中世康恺");
|
|
|
request.putQueryParameter("TemplateCode", "SMS_163620994");
|
|
|
- request.putQueryParameter("TemplateParam", "{\"code\":1223}");
|
|
|
+ request.putQueryParameter("TemplateParam", jsonObject.toJSONString());
|
|
|
try {
|
|
|
CommonResponse response = client.getCommonResponse(request);
|
|
|
- System.out.println(response.getData());
|
|
|
+ String content = response.getData();
|
|
|
+ JSONObject contentJson = JSON.parseObject(content);
|
|
|
+ if (contentJson.getString("Code").equals("OK")) {
|
|
|
+ Redis.use("weixin_doctor").setex("SMS_CODE_", 60*10, code);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
} catch (ServerException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (ClientException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return Boolean.FALSE;
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
-// sendSmsCode("");
|
|
|
- Doctors doctors = Doctors.dao.findFirst("select * from doctors where phone=?", "15203224322");
|
|
|
- String ddString = JSON.toJSONString(doctors);
|
|
|
-
|
|
|
- System.out.println(ddString);
|
|
|
-
|
|
|
+ public LoginBean checkCode(String phone,String code, String openid) {
|
|
|
+ String cacheKey = "SMS_CODE_" + phone;
|
|
|
+ String content = Redis.use("weixin_doctor").get(cacheKey);
|
|
|
+ if (content != null && content.equals(code)) {
|
|
|
+ Redis.use().del(cacheKey);
|
|
|
+ Doctors doctors = Doctors.dao.findFirst("select * from doctors where phone=?", phone);
|
|
|
+ if (doctors == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ DoctorsWechat doctorsWechat = DoctorsWechat.dao.findFirst("select * from doctors_wechat where wxa_openid=?", openid);
|
|
|
+ doctorsWechat.setDoctorId(doctors.getId());
|
|
|
+ doctorsWechat.update();
|
|
|
+ LoginBean loginBean = new LoginBean();
|
|
|
+ doctors.setPassword("");
|
|
|
+ DoctorBean doctorBean = JSON.parseObject(doctors.toJson(), DoctorBean.class);
|
|
|
+ Institution institution = Institution.dao.findById(doctorBean.getInstitution_id());
|
|
|
+ doctorBean.setInstitution(institution.getName());
|
|
|
+ StringBuilder sb = new StringBuilder(doctorBean.getPhone());
|
|
|
+ sb.replace(3, 7, "****");
|
|
|
+ doctorBean.setPhone(sb.toString());
|
|
|
+ String tokenKey = "TOKEN_WXA_" + StrKit.getRandomUUID();
|
|
|
+ Redis.use("pc").setex("think" + tokenKey, 7200, doctors.toJson());
|
|
|
+ loginBean.setDoctorBean(doctorBean);
|
|
|
+ loginBean.setToken(tokenKey);
|
|
|
+ return loginBean;
|
|
|
+ }else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 生成四位验证码
|
|
|
+ */
|
|
|
+ private String creatRandomCode() {
|
|
|
+ int max=9999;
|
|
|
+ int min=0;
|
|
|
+ Random random = new Random();
|
|
|
+ int randomNumber = random.nextInt(max)%(max-min+1) + min;
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ String strNum = String.valueOf(randomNumber);
|
|
|
+ int fixLength = 4 - strNum.length();
|
|
|
+ for (int i = 0; i < fixLength; i++) {
|
|
|
+ sb.append('0');
|
|
|
+ }
|
|
|
+ sb.append(strNum);
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|