Commit 3b68e1c6 authored by zhangyong's avatar zhangyong

1

parent 26d95675
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.4.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
......
...@@ -38,7 +38,11 @@ public class SystemCtrlController { ...@@ -38,7 +38,11 @@ public class SystemCtrlController {
String code = request.getParameter("code"); String code = request.getParameter("code");
String langID = request.getParameter("langID"); String langID = request.getParameter("langID");
Map<String, Object> result = systemCtrlService.queryTSystemCtrlByCode(code, langID);
return systemCtrlService.queryTSystemCtrlByCode(code, langID); if(result != null) {
return Rjx.jsonOk().setData(result).toJson();
}else {
return Rjx.jsonErr().setCode(-1).setMessage("数据字典查询出错").toJson();
}
} }
} }
...@@ -11,7 +11,9 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -11,7 +11,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.shop.pojo.TCustomer;
import com.egolm.shop.service.UserService; import com.egolm.shop.service.UserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -31,6 +33,7 @@ public class UserController { ...@@ -31,6 +33,7 @@ public class UserController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "districtID", dataType = "String", required = true, value = "区域编号", defaultValue = ""), @ApiImplicitParam(paramType = "query", name = "districtID", dataType = "String", required = true, value = "区域编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "组织机构", defaultValue = "SHBS"), @ApiImplicitParam(paramType = "query", name = "orgNO", dataType = "String", required = true, value = "组织机构", defaultValue = "SHBS"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"), @ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"),
}) })
...@@ -47,4 +50,100 @@ public class UserController { ...@@ -47,4 +50,100 @@ public class UserController {
} }
@ApiOperation("登陆")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "userNO", dataType = "String", required = false, value = "账号(账号/名称/手机号)", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "password", dataType = "String", required = false, value = "密码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "openID", dataType = "String", required = false, value = "openID(优先级小于账号)", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
})
@RequestMapping(value = "/login",method=RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response) {
String userNO = request.getParameter("userNO")==null?"":request.getParameter("userNO");
String password = request.getParameter("password")==null?"":request.getParameter("password");
String openID = request.getParameter("openID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("userNO", userNO);
params.put("password", password);
params.put("openID", openID);
return userService.login(params);
}
@ApiOperation("获取店铺信息")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "custNO", dataType = "String", required = true, value = "账号编码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "shopNO", dataType = "String", required = false, value = "店铺编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
})
@RequestMapping(value = "/userInfo",method=RequestMethod.GET)
public String userInfo(HttpServletRequest request, HttpServletResponse response) {
String custNO = request.getParameter("custNO");
String shopNO = request.getParameter("shopNO")==null?"":request.getParameter("shopNO");
System.out.println("shopNO===="+StringUtil.isNotEmpty(shopNO));
TCustomer tCustomer = userService.getCustomer(custNO, shopNO);
return Rjx.jsonOk().setData(tCustomer).toJson();
}
@ApiOperation("修改密码")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "password", dataType = "String", required = true, value = "店铺编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "smsCode", dataType = "String", required = true, value = "短信验证码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "smsTmpID", dataType = "String", required = true, value = "短信模板ID", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
})
@RequestMapping(value = "/modifyPwd",method=RequestMethod.GET)
public String modifyPwd(HttpServletRequest request, HttpServletResponse response) {
String mobile = request.getParameter("mobile");
String password = request.getParameter("password")==null?"":request.getParameter("password");
String smsCode = request.getParameter("smsCode")==null?"":request.getParameter("smsCode");
String langID = request.getParameter("langID")==null?"936":request.getParameter("langID");
String smsTmpID = request.getParameter("smsTmpID")==null?"936":request.getParameter("smsTmpID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("mobile", mobile);
params.put("password", password);
params.put("smsCode", smsCode);
params.put("langID", langID);
params.put("smsTmpID", smsTmpID);
return userService.modifyPwd(params);
}
@ApiOperation("发短信")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "mobile", dataType = "String", required = true, value = "手机号码", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "smsTmpID", dataType = "String", required = true, value = "短信模板ID", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "content", dataType = "String", required = true, value = "内容,按模板上的参数填值,以,分隔", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
})
@RequestMapping(value = "/sendSms",method=RequestMethod.GET)
public String sendSms(HttpServletRequest request, HttpServletResponse response) {
String mobile = request.getParameter("mobile");
String smsTmpID = request.getParameter("smsTmpID");
String content = request.getParameter("content");
String langID = request.getParameter("langID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("mobile", mobile);
params.put("langID", langID);
params.put("smsTmpID", smsTmpID);
params.put("content",content);
return userService.sendSms(params);
}
} }
package com.egolm.shop.encrypt;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
@Component("passwordEncoder")
public class EgoPasswordEncoder implements PasswordEncoder {
@Override
public String encode(CharSequence rawPassword) {
return EgoShopPasswordEncoder.encode(rawPassword.toString());
}
public String decode(CharSequence rawPassword) {
return EgoShopPasswordEncoder.decode(rawPassword.toString());
}
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
return encode(rawPassword.toString()).equals(encodedPassword);
}
public static void main(String[] args) {
EgoPasswordEncoder e = new EgoPasswordEncoder();
System.out.println(e.decode("zLnXcPGqQ/2iE2YwfoVkqXb1Ufb0bDYm"));
System.out.println(e.encode("13654804000123456"));
}
}
package com.egolm.shop.encrypt;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import com.egolm.common.StringUtil;
/**
* 数据安全加密工具类
*/
public final class EgoShopPasswordEncoder {
private static final String DEFAULT_DES_CRYPT_KEY = "EGOLMEGOLM";
private static final String DEFAULT_AES_CRYPT_KEY = "EGOLMEGOLM";
/**
* 对输入的字符串进行MD5加密
*
* @param str 需要加密的字符串
* @return MD5加密后的字符串
*/
public static String getMD5(String str) {
if (StringUtil.isEmpty(str)) {
return null;
}
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] digest = messageDigest.digest(str.getBytes());
return new String(Hex.encodeHex(digest));
} catch (NoSuchAlgorithmException e) {
return null;
}
}
/**
* 使用默认密钥进行 AES加密
*
* @param content 须加密内容
* @return 字符串
*/
@SuppressWarnings("unused")
private static String encryptAES(String content) {
return encryptAES(content, DEFAULT_AES_CRYPT_KEY);
}
/**
* AES加密
*
* @param content 须加密内容
* @param key 密钥
* @return 字符串
*/
private static String encryptAES(String content, String key) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(key.getBytes());
kgen.init(128, secureRandom);
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);// 初始化
byte[] result = cipher.doFinal(byteContent);
return parseByte2HexStr(result); // 加密
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* 使用默认密钥进行 AES解密
*
* @param content
* @return 字符串
*/
@SuppressWarnings("unused")
private static String decryptAES(String content) {
return decryptAES(content, DEFAULT_AES_CRYPT_KEY);
}
/**
* AES解密
*
* @param content 待解密内容
* @param key 解密密钥
* @return 字符串
*/
private static String decryptAES(String content, String key) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(key.getBytes());
kgen.init(128, secureRandom);
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);// 初始化
byte[] result = cipher.doFinal(parseHexStr2Byte(content));
return new String(result); // 加密
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* 使用默认密钥进行 AES加密
*
* @param content 须加密内容
* @return 字符串
*/
@SuppressWarnings("unused")
private static String encryptDES(String content) {
return encryptDES(content, DEFAULT_DES_CRYPT_KEY);
}
/**
* 加密
*
* @param src 数据源
* @param key 密钥,长度必须是8的倍数
* @return 返回加密后的数据
* @throws Exception
*/
private static String encryptDES(String src, String key) {
try {
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return parseByte2HexStr(cipher.doFinal(src.getBytes()));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* 使用默认密钥进行 DES解密
*
* @param content 待解密内容
* @return 字符串
*/
@SuppressWarnings("unused")
private static String decryptDES(String content) {
return decryptDES(content, DEFAULT_DES_CRYPT_KEY);
}
/**
* 解密
*
* @param src 数据源
* @param key 密钥,长度必须是8的倍数
* @return 返回解密后的原始数据
* @throws Exception
*/
private static String decryptDES(String src, String key) {
try {
SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
return new String(cipher.doFinal(parseHexStr2Byte(src)));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* 将二进制转换成16进制
*
* @param buf 字节数组
* @return 字符串
*/
private static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 将16进制转换为二进制
*
* @param hexStr 16进制字符串
* @return 字节数组
*/
private static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
/**
* 对字符串进行MD5编码(清机系统用户密码加密)
*
* @param str 待编码字符串
* @return 字符串
*/
@SuppressWarnings("unused")
private static String encodeByMD5(String str) {
if (StringUtil.isEmpty(str)) {
return null;
}
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] digest = messageDigest.digest(str.getBytes());
return new String(Hex.encodeHex(digest));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
/**
* DES解密数据
*
* @param message
* @param key
* @return
* @throws Exception
*/
private static String decrypt(String message, String key) throws Exception {
byte[] bytesrc = convertHexString(message);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] retByte = cipher.doFinal(bytesrc);
return new String(retByte);
}
/**
* DES加密数据
*
* @param message
* @param key
* @return
* @throws Exception
*/
private static byte[] encrypt(String message, String key) throws Exception {
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
return cipher.doFinal(message.getBytes("UTF-8"));
}
private static byte[] convertHexString(String ss) {
byte digest[] = new byte[ss.length() / 2];
for (int i = 0; i < digest.length; i++) {
String byteString = ss.substring(2 * i, 2 * i + 2);
int byteValue = Integer.parseInt(byteString, 16);
digest[i] = (byte) byteValue;
}
return digest;
}
/**
* Base64加密
*
* @param sourceByte
* @return
*/
private static String doBase64Encode(byte[] sourceByte) {
String src = Base64.encodeBase64String(sourceByte);
return src.replace("\n", "");
}
/**
* Base64解密
*
* @param sourceByte
* @return
*/
private static byte[] doBase64Decode(String sourceStr) {
return Base64.decodeBase64(sourceStr);
}
private static String doHandleEncode(String value, String skey) {
String jiami;
try {
jiami = java.net.URLEncoder.encode(value, "utf-8").toLowerCase();
byte[] encodeByte = encrypt(jiami, skey);
return doBase64Encode(encodeByte);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
private static String doHandleDecode(String value, String skey) {
byte[] decodeByte = doBase64Decode(value);
try {
return java.net.URLDecoder.decode(decrypt(toHexString(decodeByte), skey), "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String encode(String value) {
return doHandleEncode(value, "donguooo");
}
public static String decode(String value) {
return doHandleDecode(value, "donguooo");
}
private static String toHexString(byte b[]) {
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
String plainText = Integer.toHexString(0xff & b[i]);
if (plainText.length() < 2)
plainText = "0" + plainText;
hexString.append(plainText);
}
return hexString.toString();
}
@SuppressWarnings("unused")
private static String SHA1(String decript) {
try {
MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1");
digest.update(decript.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
// 字节数组转换为 十六进制 数
for (int i = 0; i < messageDigest.length; i++) {
String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
if (shaHex.length() < 2) {
hexString.append(0);
}
hexString.append(shaHex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
@SuppressWarnings("unused")
private static boolean decryptSha1(String src, byte[] desc) // 如果这里传入的是byte[]
// 转换后的字符串,则再转为字符串比较后,会匹配不成功
{
// MessageDigest sha1 = MessageDigest.getInstance("sha-1");
try {
java.security.MessageDigest algb = java.security.MessageDigest.getInstance("sha-1");
algb.update(src.getBytes());
System.out.println(toHexString(algb.digest()));
System.out.println(toHexString(algb.digest()));
if (MessageDigest.isEqual(desc, algb.digest())) {
System.out.println("信息检查正常");
return true;
} else {
System.out.println("摘要不相同");
}
} catch (java.security.NoSuchAlgorithmException ex) {
System.out.println("非法摘要算法");
}
return false;
}
public static void main(String[] args) {
// System.out.println(encryptAES("123456"));
// System.out.println(decryptAES(encryptAES("123456")));
// String key = "donguooo";
// String value="1333333333612345";
/*
* String jiami=java.net.URLEncoder.encode(value,"utf-8").toLowerCase();
* //System.out.println("加密数据:"+jiami); byte[] aa = encrypt(jiami, key);
* //String a=toHexString(aa).toUpperCase(); String src =
* org.apache.ws.commons.util.Base64.encode(aa);
* System.out.println("Base64加密后:"+src); aa =
* org.apache.ws.commons.util.Base64.decode(src);
* System.out.println("Base64解密后:"+toHexString(aa)); String
* b=java.net.URLDecoder.decode(decrypt(toHexString(aa),key),"utf-8") ;
* System.out.println("解密后的数据:"+b);
*/
// String str = doHandleEncode(value, key);
// System.out.println(str);
// System.out.println(doHandleDecode("8yxntpc9QX04dHCT9dzQ4Yk7xcppKdA5R0GR8oJZXT30s38LVXhG7XlZRTxkzcWY",
// key));
// System.out.println(toHexString(doBase64Decode("MTIzNDU2")));
// System.out.println(wxPasswordDecode("E10ADC3949BA59ABBE56E057F20F883E"));
System.out.println(encode("XIAN123456"));
System.out.println(decode("gj7BU4Rm2W27GG5KexzYRw=="));
}
}
package com.egolm.shop.pojo;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
import java.math.BigDecimal;
/**
* @author 曲欣亮
* @since 2018-10-09
* @version v-1.0
*/
@Entity(name="tCommon")
public class TCommon implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Date dCreateDate;
private String sComDesc;
private Date dLastUpdateTime;
private String sMemo;
private Integer nTag;
@Id
private String sCommonNO;
private String sConfirmUser;
private BigDecimal nNum1;
private String sText1;
@Id
private String sComID;
private Date dConfirmDate;
private String sCreateUser;
/**
* 无参数构造方法
*/
public TCommon () {
super();
}
/**
* 全参数构造方法
* @param dCreateDate
* @param sComDesc
* @param dLastUpdateTime
* @param sMemo
* @param nTag
* @param sCommonNO
* @param sConfirmUser
* @param nNum1
* @param sText1
* @param sComID
* @param dConfirmDate
* @param sCreateUser
*/
public TCommon(Date dCreateDate, String sComDesc, Date dLastUpdateTime, String sMemo, Integer nTag, String sCommonNO, String sConfirmUser, BigDecimal nNum1, String sText1, String sComID, Date dConfirmDate, String sCreateUser) {
this.dCreateDate = dCreateDate;
this.sComDesc = sComDesc;
this.dLastUpdateTime = dLastUpdateTime;
this.sMemo = sMemo;
this.nTag = nTag;
this.sCommonNO = sCommonNO;
this.sConfirmUser = sConfirmUser;
this.nNum1 = nNum1;
this.sText1 = sText1;
this.sComID = sComID;
this.dConfirmDate = dConfirmDate;
this.sCreateUser = sCreateUser;
}
public void setdCreateDate(Date dCreateDate) {
this.dCreateDate = dCreateDate;
}
public Date getdCreateDate() {
return dCreateDate;
}
public void setsComDesc(String sComDesc) {
this.sComDesc = sComDesc;
}
public String getsComDesc() {
return sComDesc;
}
public void setdLastUpdateTime(Date dLastUpdateTime) {
this.dLastUpdateTime = dLastUpdateTime;
}
public Date getdLastUpdateTime() {
return dLastUpdateTime;
}
public void setsMemo(String sMemo) {
this.sMemo = sMemo;
}
public String getsMemo() {
return sMemo;
}
public void setnTag(Integer nTag) {
this.nTag = nTag;
}
public Integer getnTag() {
return nTag;
}
public void setsCommonNO(String sCommonNO) {
this.sCommonNO = sCommonNO;
}
public String getsCommonNO() {
return sCommonNO;
}
public void setsConfirmUser(String sConfirmUser) {
this.sConfirmUser = sConfirmUser;
}
public String getsConfirmUser() {
return sConfirmUser;
}
public void setnNum1(BigDecimal nNum1) {
this.nNum1 = nNum1;
}
public BigDecimal getnNum1() {
return nNum1;
}
public void setsText1(String sText1) {
this.sText1 = sText1;
}
public String getsText1() {
return sText1;
}
public void setsComID(String sComID) {
this.sComID = sComID;
}
public String getsComID() {
return sComID;
}
public void setdConfirmDate(Date dConfirmDate) {
this.dConfirmDate = dConfirmDate;
}
public Date getdConfirmDate() {
return dConfirmDate;
}
public void setsCreateUser(String sCreateUser) {
this.sCreateUser = sCreateUser;
}
public String getsCreateUser() {
return sCreateUser;
}
}
...@@ -67,7 +67,7 @@ public class TCustomer implements java.io.Serializable { ...@@ -67,7 +67,7 @@ public class TCustomer implements java.io.Serializable {
private String sFax; private String sFax;
private List<TShop> tshop ; private List<TShop> tshops ;
/** /**
* 无参数构造方法 * 无参数构造方法
...@@ -132,12 +132,14 @@ public class TCustomer implements java.io.Serializable { ...@@ -132,12 +132,14 @@ public class TCustomer implements java.io.Serializable {
public List<TShop> getTshop() {
return tshop;
public List<TShop> getTshops() {
return tshops;
} }
public void setTshop(List<TShop> tshop) { public void setTshops(List<TShop> tshops) {
this.tshop = tshop; this.tshops = tshops;
} }
public void setToken(String token) { public void setToken(String token) {
......
package com.egolm.shop.service; package com.egolm.shop.service;
import java.util.List;
import com.egolm.shop.pojo.TCommon;
public interface CommonService { public interface CommonService {
/** /**
* 保存浏览记录 * 保存浏览记录
...@@ -10,4 +14,6 @@ public interface CommonService { ...@@ -10,4 +14,6 @@ public interface CommonService {
* @param values * @param values
*/ */
public void saveViewHistory(String zone,String terminalTypeID,String shopNO,String viewTypeID,String values); public void saveViewHistory(String zone,String terminalTypeID,String shopNO,String viewTypeID,String values);
public List<TCommon> getTCommon(String commonNO,String comID);
} }
package com.egolm.shop.service; package com.egolm.shop.service;
import java.util.Map;
public interface SystemCtrlService { public interface SystemCtrlService {
public String queryTSystemCtrlByCode(String sCode,String langID); public Map<String, Object> queryTSystemCtrlByCode(String sCode,String langID);
} }
...@@ -8,7 +8,15 @@ import com.egolm.shop.pojo.TShop; ...@@ -8,7 +8,15 @@ import com.egolm.shop.pojo.TShop;
public interface UserService { public interface UserService {
public TCustomer getCustomer(String custNO,String shopNO); public TCustomer getCustomer(String custNO,String shopNO);
public TCustomer getCustomer(String mobile);
public TShop getShop(String shopNO); public TShop getShop(String shopNO);
public Map<String,Object> createGuest(Map<String,Object> params); public Map<String,Object> createGuest(Map<String,Object> params);
public String login(Map<String,Object> params) ;
public String modifyPwd(Map<String,Object> params);
public String sendSms(Map<String,Object> params);
} }
...@@ -59,7 +59,7 @@ public class CategoryServiceImpl implements CategoryService { ...@@ -59,7 +59,7 @@ public class CategoryServiceImpl implements CategoryService {
} }
return Rjx.jsonOk().setData(list1).toJson(); return Rjx.jsonOk().setData(list1).toJson();
}catch(Exception e) { }catch(Exception e) {
return Rjx.jsonErr().setMessage("分类查询出错").toJson(); return Rjx.jsonErr().setCode(-1).setMessage("分类查询出错").toJson();
} }
} }
......
package com.egolm.shop.service.impl; package com.egolm.shop.service.impl;
import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.egolm.shop.pojo.TCommon;
import com.egolm.shop.service.CommonService; import com.egolm.shop.service.CommonService;
@Service @Service
...@@ -25,6 +30,7 @@ public class CommonServiceImpl implements CommonService{ ...@@ -25,6 +30,7 @@ public class CommonServiceImpl implements CommonService{
*/ */
public void saveViewHistory(String zone,String terminalTypeID,String shopNO,String viewTypeID,String values){ public void saveViewHistory(String zone,String terminalTypeID,String shopNO,String viewTypeID,String values){
try{ try{
jdbcTemplate.setDialect(new SqlServerDialect());
String checkSql="SELECT " String checkSql="SELECT "
+ " COUNT(1) " + " COUNT(1) "
+ "FROM " + "FROM "
...@@ -57,4 +63,18 @@ public class CommonServiceImpl implements CommonService{ ...@@ -57,4 +63,18 @@ public class CommonServiceImpl implements CommonService{
logger.error("浏览记录保存失败"+e); logger.error("浏览记录保存失败"+e);
} }
} }
public List<TCommon> getTCommon(String commonNO,String comID){
List<TCommon> commList = null;
jdbcTemplate.setDialect(new SqlServerDialect());
String sql = " SELECT * FROM tCommon WHERE nTag&1=0 AND sCommonNO = ? ";
if(StringUtil.isNotEmpty(comID)) {
sql += " and sComID = ? ";
commList = jdbcTemplate.queryForBeans(sql, TCommon.class, commonNO,comID);
}else {
commList = jdbcTemplate.queryForBeans(sql, TCommon.class, commonNO);
}
return commList;
}
} }
...@@ -210,7 +210,7 @@ public class GoodsServiceImpl implements GoodsService { ...@@ -210,7 +210,7 @@ public class GoodsServiceImpl implements GoodsService {
//正式用户保存浏览记录 //正式用户保存浏览记录
if(!customer.getsCustLeveTypeID().equals(ShopContstrant.GUEST_LEVEL_TYPE_ID)) { if(!customer.getsCustLeveTypeID().equals(ShopContstrant.GUEST_LEVEL_TYPE_ID)) {
commonService.saveViewHistory(customer.getTshop().get(0).getsOrgNO(), terminal, shopNO, "1", goodsID); commonService.saveViewHistory(customer.getTshops().get(0).getsOrgNO(), terminal, shopNO, "1", goodsID);
} }
Map<String,Object> goodsDetailMap = jdbcTemplate.queryForMap(goodsInfoSql); Map<String,Object> goodsDetailMap = jdbcTemplate.queryForMap(goodsInfoSql);
...@@ -277,7 +277,7 @@ public class GoodsServiceImpl implements GoodsService { ...@@ -277,7 +277,7 @@ public class GoodsServiceImpl implements GoodsService {
if(customer == null) { if(customer == null) {
return Rjx.jsonErr().setMessage("用户不存在").toJson(); return Rjx.jsonErr().setMessage("用户不存在").toJson();
} }
TShop shop = customer.getTshop().get(0); TShop shop = customer.getTshops().get(0);
String districtID = shop.getsDistrictID(); String districtID = shop.getsDistrictID();
...@@ -313,7 +313,7 @@ public class GoodsServiceImpl implements GoodsService { ...@@ -313,7 +313,7 @@ public class GoodsServiceImpl implements GoodsService {
return Rjx.jsonOk().setMessage("取消收藏成功").toJson(); return Rjx.jsonOk().setMessage("取消收藏成功").toJson();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return Rjx.jsonErr().setMessage("取消收藏失败").toJson(); return Rjx.jsonErr().setCode(-1).setMessage("取消收藏失败").toJson();
} }
}else if("1".equals(override)) { }else if("1".equals(override)) {
try { try {
...@@ -321,9 +321,9 @@ public class GoodsServiceImpl implements GoodsService { ...@@ -321,9 +321,9 @@ public class GoodsServiceImpl implements GoodsService {
return Rjx.jsonOk().setMessage("收藏成功").toJson(); return Rjx.jsonOk().setMessage("收藏成功").toJson();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return Rjx.jsonErr().setMessage("收藏失败").toJson(); return Rjx.jsonErr().setCode(-1).setMessage("收藏失败").toJson();
} }
} }
return Rjx.jsonErr().setMessage("操作失败").toJson(); return Rjx.jsonErr().setCode(-1).setMessage("操作失败").toJson();
} }
} }
...@@ -23,7 +23,7 @@ public class GoodsSql { ...@@ -23,7 +23,7 @@ public class GoodsSql {
public static String goodsInfoSql(TCustomer customer,Map<String, Object> map) { public static String goodsInfoSql(TCustomer customer,Map<String, Object> map) {
String goodsID=(String) map.get("goodsID"); String goodsID=(String) map.get("goodsID");
String contractNO=(String) map.get("contractNO"); String contractNO=(String) map.get("contractNO");
TShop tshop = customer.getTshop().get(0); TShop tshop = customer.getTshops().get(0);
String goodInfoSql = ""; String goodInfoSql = "";
if(customer.getsCustLeveTypeID().equals(ShopContstrant.GUEST_LEVEL_TYPE_ID)) { //游客 if(customer.getsCustLeveTypeID().equals(ShopContstrant.GUEST_LEVEL_TYPE_ID)) { //游客
goodInfoSql="SELECT TOP 1 " goodInfoSql="SELECT TOP 1 "
......
...@@ -20,14 +20,14 @@ public class SystemCtrlServiceImpl implements SystemCtrlService { ...@@ -20,14 +20,14 @@ public class SystemCtrlServiceImpl implements SystemCtrlService {
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
public String queryTSystemCtrlByCode(String sCode,String langID) { public Map<String, Object> queryTSystemCtrlByCode(String sCode,String langID) {
try { try {
String sql = "select sDesc, sSysTypeID, sSysType, sValue1, sValue2, sValue3, sMemo from tSystemCtrl where sCode = ? and nTag&1 = 0"; String sql = "select sDesc, sSysTypeID, sSysType, sValue1, sValue2, sValue3, sMemo from tSystemCtrl where sCode = ? and nTag&1 = 0";
Map<String, Object> mapRsult = jdbcTemplate.queryForMap(sql,sCode); Map<String, Object> mapRsult = jdbcTemplate.queryForMap(sql,sCode);
return Rjx.jsonOk().setData(mapRsult).toJson(); return mapRsult;
}catch (Exception e) { }catch (Exception e) {
logger.error("数据字典查询出错: "+e.getMessage()); logger.error("数据字典查询出错: "+e.getMessage());
return Rjx.jsonErr().setMessage("数据字典查询出错").toJson(); return null;
} }
} }
} }
package com.egolm.shop.service.impl; package com.egolm.shop.service.impl;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -12,11 +15,18 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -12,11 +15,18 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.HttpsUtil;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.SqlServerDialect; import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.egolm.shop.encrypt.EgoPasswordEncoder;
import com.egolm.shop.pojo.TCommon;
import com.egolm.shop.pojo.TCustomer; import com.egolm.shop.pojo.TCustomer;
import com.egolm.shop.pojo.TShop; import com.egolm.shop.pojo.TShop;
import com.egolm.shop.service.CommonService;
import com.egolm.shop.service.SystemCtrlService;
import com.egolm.shop.service.UserService; import com.egolm.shop.service.UserService;
import com.egolm.shop.util.ShopContstrant; import com.egolm.shop.util.ShopContstrant;
@Service @Service
...@@ -28,11 +38,20 @@ public class UserServiceImpl implements UserService { ...@@ -28,11 +38,20 @@ public class UserServiceImpl implements UserService {
@Value("${redis.guest.key}") @Value("${redis.guest.key}")
private String guestRedisKey; private String guestRedisKey;
@Value("${redis.sms.code.key}")
private String smsCodeReidsKey;
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired
private CommonService commonService;
@Autowired
private SystemCtrlService systemCtlService;
public TCustomer getCustomer(String custNO,String shopNO) { public TCustomer getCustomer(String custNO,String shopNO) {
if (custNO.contains(ShopContstrant.CUST_SIGN)) { if (custNO.contains(ShopContstrant.CUST_SIGN)) {
TCustomer redisCust = (TCustomer)redisTemplate.opsForHash().get(guestRedisKey, custNO); TCustomer redisCust = (TCustomer)redisTemplate.opsForHash().get(guestRedisKey, custNO);
...@@ -43,12 +62,16 @@ public class UserServiceImpl implements UserService { ...@@ -43,12 +62,16 @@ public class UserServiceImpl implements UserService {
jdbcTemplate.setDialect(new SqlServerDialect()); jdbcTemplate.setDialect(new SqlServerDialect());
TCustomer tcustomer = jdbcTemplate.queryForBean(sql, TCustomer.class, custNO); TCustomer tcustomer = jdbcTemplate.queryForBean(sql, TCustomer.class, custNO);
List<TShop> shops = null;
String shopSql = "SELECT * FROM tShop WHERE nTag&1=0 and sCustNO =? "; String shopSql = "SELECT * FROM tShop WHERE nTag&1=0 and sCustNO =? ";
if(StringUtil.isNotEmpty(shopNO)) { if(StringUtil.isNotEmpty(shopNO)) {
shopSql += " AND sShopNO = ? "; shopSql += " AND sShopNO = ? ";
shops = jdbcTemplate.queryForBeans(shopSql, TShop.class, custNO.trim(),shopNO.trim());
}else {
shops = jdbcTemplate.queryForBeans(shopSql, TShop.class, custNO.trim());
} }
List<TShop> shops = jdbcTemplate.queryForBeans(shopSql, TShop.class, custNO,shopNO);
tcustomer.setTshop(shops); tcustomer.setTshops(shops);
return tcustomer; return tcustomer;
} catch (Exception e) { } catch (Exception e) {
...@@ -57,6 +80,17 @@ public class UserServiceImpl implements UserService { ...@@ -57,6 +80,17 @@ public class UserServiceImpl implements UserService {
} }
} }
public TCustomer getCustomer(String mobile) {
try {
String sql = "SELECT * FROM tCustomer WHERE sMobile = ? AND nTag&1=0";
return jdbcTemplate.queryForBean(sql, TCustomer.class, mobile);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public TShop getShop(String shopNO) { public TShop getShop(String shopNO) {
if (StringUtil.isEmpty(shopNO)) { if (StringUtil.isEmpty(shopNO)) {
return new TShop(); return new TShop();
...@@ -91,7 +125,7 @@ public class UserServiceImpl implements UserService { ...@@ -91,7 +125,7 @@ public class UserServiceImpl implements UserService {
List<TShop> listShop = new ArrayList<TShop>(); List<TShop> listShop = new ArrayList<TShop>();
listShop.add(tshop); listShop.add(tshop);
customer.setTshop(listShop); customer.setTshops(listShop);
redisTemplate.opsForHash().put(guestRedisKey, custNO, customer); redisTemplate.opsForHash().put(guestRedisKey, custNO, customer);
Map<String,Object> map = new HashMap<String,Object>(); Map<String,Object> map = new HashMap<String,Object>();
...@@ -106,4 +140,239 @@ public class UserServiceImpl implements UserService { ...@@ -106,4 +140,239 @@ public class UserServiceImpl implements UserService {
return map; return map;
} }
/**
* 登陆 优先级: 账号 > openID
* @Title: login
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param params
* @param: @return
* @return: String
* @throws
*/
public String login(Map<String,Object> params) {
String userNO = params.get("userNO")+"";
String password = params.get("password")+"";
String openID = params.get("openID")+"";
jdbcTemplate.setDialect(new SqlServerDialect());
if(StringUtil.isNotEmpty(userNO)) { //优先用户
EgoPasswordEncoder epe = new EgoPasswordEncoder();
String newPwd = epe.encode(userNO+password);
System.out.println("userNO----"+userNO+"-----newPwd---"+newPwd);
String checkUserSql = " SELECT count(1) FROM tCustomer t where nTag&1 = 0 and (t.sCustNO=? or t.sMobile =? or t.sCustName = ? ) and t.sPassword = ? ";
int i = jdbcTemplate.queryForInt(checkUserSql,userNO,userNO,userNO,newPwd);
System.out.println(i);
if(i != 0) {
if(StringUtil.isNotEmpty(openID)) { //openid不为空,则更新为新的
jdbcTemplate.update("update tCustomer set sOpenID=null,dLastUpdateTime=GETDATE() where sOpenID='"+openID+"' ");
jdbcTemplate.executeUpdate("update tCustomer set sOpenID=?, sBindOpenID=?, dLastUpdateTime=GETDATE() where sCustNO=?",openID,openID,userNO);
}
return Rjx.jsonOk().set("custNO", userNO).setMessage("登陆成功").toJson();
}else {
return Rjx.jsonErr().setCode(-1).setMessage("用户名或密码错误").toJson();
}
}else {
if(StringUtil.isNotEmpty(openID)) { //openID登陆
String checkOpenSql = " SELECT t.sCustNO FROM tCustomer t where t.sOpenID =? and nTag&1 = 0 ";
List<Map<String,Object>> list = jdbcTemplate.queryForList(checkOpenSql,openID.trim());
if(list != null) {
if(list.size() == 1) {
Map<String,Object> map = list.get(0);
String custNO = map.get("sCustNO")+"";
return Rjx.jsonOk().setMessage("登陆成功").set("custNO",custNO).toJson();
}else {
return Rjx.jsonErr().setCode(-1).setMessage("登陆失败").set("errorMsg","openID存在多条数据").toJson();
}
}else {
return Rjx.jsonErr().setCode(-1).setMessage("登陆失败").set("errorMsg", "openId不存在").toJson();
}
}
}
return Rjx.jsonErr().setCode(-1).setMessage("登陆失败").toJson();
}
/**
* 修改密码
* @Title: modifyPwd
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param params
* @param: @return
* @return: String
* @throws
*/
public String modifyPwd(Map<String,Object> params) {
String mobile = params.get("mobile")+"";
String password = params.get("password")+"";
String smsCode = params.get("smsCode")+"";
String smsTmpID = params.get("smsTmpID")+"";
//检查手机号是否存在
TCustomer customer = getCustomer(mobile);
if(customer == null) {
return Rjx.jsonErr().setCode(-1).setMessage("手机号不存在").toJson();
}
//验证redis中是否在短信验证码
if(isCheckCodeByRedis(mobile, smsTmpID)) {
String redisCode = (String) redisTemplate.opsForHash().get(smsCodeReidsKey, mobile+"_"+smsTmpID);
System.out.println("smsCode-----"+smsCode);
System.out.println("redisCode-----"+redisCode);
if(!smsCode.equals(redisCode)) {
return Rjx.jsonOk().setCode(-1).setMessage("验证码不匹配").toJson();
}else {
redisTemplate.opsForHash().delete(smsCodeReidsKey, mobile+"_"+smsTmpID);
}
}
//较验
jdbcTemplate.setDialect(new SqlServerDialect());
EgoPasswordEncoder epe = new EgoPasswordEncoder();
String newPwd = epe.encode(mobile+password);
String updateSql = "UPDATE tCustomer SET sPassword = ? ,dLastUpdateTime = getdate() WHERE sMobile = ? AND nTag&1=0 ";
int i = jdbcTemplate.update(updateSql, newPwd,mobile);
if(i >0) {
return Rjx.jsonOk().setMessage("密码修改成功").toJson();
}else {
return Rjx.jsonOk().setCode(-1).setMessage("密码修改失败").toJson();
}
}
/**
* 发送短信
* <p>Title: sendSms</p>
* <p>Description: </p>
* content 根据模板 对应多个参数,以逗号分隔 模板格式示例: 这是是一个{0}的模板{1}
* @param params
* @return
* @see com.egolm.shop.service.UserService#sendSms(java.util.Map)
*/
@Override
public String sendSms(Map<String, Object> params) {
String mobile = params.get("mobile")+"";
String content = params.get("content")+"";
String smsTmpID = params.get("smsTmpID")+"";
String langID = params.get("langID")+"";
content = getSmsContent(mobile,content, smsTmpID);
if(!StringUtil.isNotEmpty(content)) {
return Rjx.jsonErr().setCode(-1).setMessage("短信发送失败").set("errorMsg","短信内容不能为空").toJson();
}
return sendCallSms(mobile, content, langID);
}
/**
* 调用短信sms服务,发送短信
* @Title: sendCallSms
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param mobile
* @param: @param content
* @param: @param langID
* @param: @return
* @return: String
* @throws
*/
private String sendCallSms(String mobile,String content,String langID) {
jdbcTemplate.setDialect(new SqlServerDialect());
Map<String, Object> ctrlMap = systemCtlService.queryTSystemCtrlByCode(ShopContstrant.CHOICE_SMS_KEY, langID);
if(ctrlMap != null) {
String value1 = ctrlMap.get("sValue1")+"";
if(StringUtil.isNotEmpty(value1)) {
Map<String, Object> smsCtrlMap = systemCtlService.queryTSystemCtrlByCode(value1, langID);
if(smsCtrlMap != null) {
String smsType = smsCtrlMap.get("sValue1")+"";
String smsMd5 = smsCtrlMap.get("sValue2")+"";
String smsUrl = smsCtrlMap.get("sValue3")+"";
Map<String,String> smsMap = new HashMap<String,String>();
smsMap.put("mobile", mobile);
smsMap.put("content", content);
smsMap.put("timestamp", (new Date().getTime())+"");
smsMap.put("smsType", smsType);
smsMap.put("md5Key", smsMd5);
String sign = StringUtil.doMD5Sign(smsMap);
smsMap.remove("md5Key");
smsMap.put("sign", sign);
String smsResult = HttpsUtil.doGet(smsUrl, smsMap);
JSONObject jsonObj = JSONObject.parseObject(smsResult);
boolean flag = jsonObj.getBoolean("isValid");
System.out.println("jsonObj----"+jsonObj);
if(flag) {
return Rjx.jsonOk().setMessage("短信发送成功").toJson();
}else {
return Rjx.jsonErr().setCode(-1).setMessage("短信发送失败").set("errorMsg", jsonObj.get("msg")).toJson();
}
}else {
return Rjx.jsonErr().setCode(-1).setMessage("短信发送失败").set("errorMsg","短信网关未配置").toJson();
}
}else {
return Rjx.jsonErr().setCode(-1).setMessage("短信发送失败").set("errorMsg","短信选择器未配置").toJson();
}
}else {
return Rjx.jsonErr().setCode(-1).setMessage("短信发送失败").set("errorMsg","短信选择器参数未配置").toJson();
}
}
/**
* 格式化短信模板为短信内容
* @Title: getSmsContent
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param content
* @param: @param smsTmpID
* @param: @return
* @return: String
* @throws
*/
private String getSmsContent(String mobile, String content,String smsTmpID) {
List<TCommon> commList = commonService.getTCommon(ShopContstrant.SMS_TEMPLATE_CODE, smsTmpID);
if(commList != null && commList.size()>0) {
TCommon common = commList.get(0);
String text = common.getsText1();
BigDecimal num = common.getnNum1();
if(smsTmpID.equals("1")) { //验证码短信 num1字段0值表示由前端自已生成验证码并存储,1值为由后端生成并缓存验证码至redis ,修改时需要验证
if(num.compareTo(new BigDecimal(1)) == 0) {
content = StringUtil.getRandom(6);
redisTemplate.opsForHash().put(smsCodeReidsKey, mobile.trim()+"_"+smsTmpID, content);
}
}
String[] objs = content.split(",");
text = MessageFormat.format(text, objs);
return text;
}else {
return null;
}
}
/**
* 判断验证码是否要与redis中进行验证
* @Title: isCheckCodeByRedis
* @Description: num1字段0值表示由前端自已生成验证码并存储,1值为由后端生成并缓存验证码至redis
* @param: @param mobile
* @param: @param smsTmpID
* @param: @return
* @return: boolean
* @throws
*/
public boolean isCheckCodeByRedis(String mobile,String smsTmpID) {
List<TCommon> commList = commonService.getTCommon(ShopContstrant.SMS_TEMPLATE_CODE, smsTmpID);
if(commList != null && commList.size()>0) {
TCommon common = commList.get(0);
BigDecimal num = common.getnNum1();
if(num.compareTo(new BigDecimal(1)) == 0) {
return true;
}
}
return false;
}
} }
...@@ -5,4 +5,10 @@ public class ShopContstrant { ...@@ -5,4 +5,10 @@ public class ShopContstrant {
public static final String CUST_SIGN = "T_"; //游客账号标记 public static final String CUST_SIGN = "T_"; //游客账号标记
public static final String GUEST_LEVEL_TYPE_ID = "-1" ;// 游客 custLevelTypeID 状态 public static final String GUEST_LEVEL_TYPE_ID = "-1" ;// 游客 custLevelTypeID 状态
//短信
public static final String CHOICE_SMS_KEY= "ChoiceSmsKey"; // 短信选择器
public static final String SMS_TEMPLATE_CODE = "SmsTemplate"; //模板字典 code tcommon表
} }
...@@ -32,4 +32,7 @@ spring.redis.pool.max-wait=2000 ...@@ -32,4 +32,7 @@ spring.redis.pool.max-wait=2000
spring.redis.pool.max-idle=5 spring.redis.pool.max-idle=5
spring.redis.pool.min-idle=0 spring.redis.pool.min-idle=0
### 游客 用户生成用户的前缀
redis.guest.key=B2B_Guest redis.guest.key=B2B_Guest
#### 用户验证码存储的前缀
redis.sms.code.key=B2B_Sms
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment