Files
redbbs-pro/src/com/lxyer/bbs/weixin/WeiXinService.java
2019-05-01 11:11:42 +08:00

85 lines
2.3 KiB
Java

package com.lxyer.bbs.weixin;
import com.lxyer.bbs.base.BaseService;
import com.lxyer.bbs.base.user.UserService;
import com.lxyer.bbs.comment.CommentService;
import com.lxyer.bbs.content.ContentService;
import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestService;
import org.redkale.util.Utility;
import org.redkalex.cache.RedisCacheSource;
import org.redkalex.weixin.WeiXinMPService;
import javax.annotation.Resource;
import java.io.File;
import java.security.MessageDigest;
import java.util.Arrays;
/**
* Created by JUECHENG at 2018/1/12 0:14.
*/
@RestService(name = "wx",automapping = true, comment = "微信管理")
public class WeiXinService extends BaseService{
private String mptoken = "redbbs_dev";
@Resource(name = "redis")
private RedisCacheSource cacheSource;
//用于微信登录
@Resource
private WeiXinMPService wxService;
@Resource
private ContentService contentService;
@Resource
private CommentService commentService;
@Resource
private UserService userService;
@Resource(name = "SERVER_ROOT")
protected File webroot;
@RestMapping(name = "verifyMPURL",auth = false, comment = "微信域名验证")
public long verifyMPURL(String msgSignature, String timeStamp, String nonce, String echoStr) {
String o = cacheSource.getString("300");
cacheSource.set("t", "");
long d = cacheSource.getLong("d", 0);
cacheSource.incr("d");
cacheSource.setExpireSeconds("d", 5);
Object t = cacheSource.getString("t");
/*String signature = sha1(mptoken, timeStamp, nonce);
if (!signature.equals(msgSignature)) throw new RuntimeException("signature verification error");
return echoStr;*/
return d;
}
/**
* 用SHA1算法生成安全签名
* <p>
* @param strings String[]
*
* @return 安全签名
*/
protected static String sha1(String... strings) {
try {
Arrays.sort(strings);
MessageDigest md = MessageDigest.getInstance("SHA-1");
for (String s : strings) md.update(s.getBytes());
return Utility.binToHexString(md.digest());
} catch (Exception e) {
throw new RuntimeException("SHA encryption to generate signature failure", e);
}
}
}