Commit 81cf6e4e authored by liuchao's avatar liuchao
parents 8c715f46 038e3099
......@@ -29,6 +29,13 @@ public class WxMaProperties {
config.setSecret(rb.getString("rainbowplan.secret"));
configs = Lists.newArrayList();
configs.add(config);
Config mdpConfig = new Config();
mdpConfig.setAppid(rb.getString("tjmdp.appid"));
mdpConfig.setSecret(rb.getString("tjmdp.secret"));
configs.add(mdpConfig);
}
public static class Config {
......
package com.qiankun.controller.mdp;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.common.collect.Maps;
import com.qiankun.annotation.Auth;
import com.qiankun.config.WxMaConfiguration;
import com.qiankun.config.WxMaProperties;
import com.qiankun.entity.User;
import com.qiankun.service.UserService;
import com.qiankun.utils.JwtTokenUtil;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.ResourceBundle;
@RestController
@RequestMapping("/wx/mdp")
public class MdpController {
private final Logger logger = LoggerFactory.getLogger(MdpController.class);
@Autowired
private JwtTokenUtil tokenUtil;
@Autowired
private WxMaProperties propertis;
@Autowired
private UserService userService;
private ResourceBundle rb = ResourceBundle.getBundle("system");
private String getAppid(){
return propertis.getConfigs().get(1).getAppid();
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/login",method = RequestMethod.GET)
public Map<String,Object> login(@RequestParam String code){
if (StringUtils.isBlank(code)) {
return null;
}
final WxMaService wxService = WxMaConfiguration.getMaService(getAppid());
try {
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
this.logger.info(session.getSessionKey());
this.logger.info(session.getOpenid());
Map<String,Object> result = Maps.newConcurrentMap();
User userInfo = userService.findByOpenid(session.getOpenid());
if (userInfo != null){
String sKey = tokenUtil.generateToken(userInfo.getOpenid());
result.put("sKey",sKey);
result.put("userInfo",userInfo);
}else {
result.put("sKey","");
result.put("userInfo","");
result.put("openid",session.getOpenid());
}
return result;
} catch (WxErrorException e) {
this.logger.error(e.getMessage(), e);
return null;
}
}
}
package com.qiankun.controller.rainbowplan;
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.common.base.Strings;
......@@ -296,6 +297,21 @@ public class RainbowPlanController {
}
}
@Auth(verifyURL = false,verifyLogin = false)
@RequestMapping(value = "/qrcode",method = RequestMethod.GET)
public ResponseEntity<byte[]> getQrcode(@RequestHeader String sKey) throws WxErrorException {
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
WxMaService wxMaService = WxMaConfiguration.getMaService(getAppid());
WxMaQrcodeService qrcodeService = wxMaService.getQrcodeService();
byte[] codeBytes = qrcodeService.createWxaCodeUnlimitBytes("inviter="+openid,"pages/register",360,true,null,false);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(codeBytes,headers,HttpStatus.OK);
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/loadResource",method = RequestMethod.GET)
......
......@@ -17,4 +17,5 @@ public interface UserDao extends IDao<User, String> {
Boolean validateUserExistByUserName(String userName);
User findByOpenid(String openid);
}
......@@ -26,6 +26,7 @@ public class UserDaoImpl extends AbsDao<User, String> implements UserDao {
private static final String VALIDATE_USERNAME = " from User where userName = ?";
private static final String VALIDATE_PWD = " from User where id = ? and pwd = ? and isRemove=false";
private static final String FIND_BY_OPENID = "from User where openid = ?";
@Override
public Boolean validateUserExistByPaperId(String paperId) {
......@@ -106,4 +107,9 @@ public class UserDaoImpl extends AbsDao<User, String> implements UserDao {
return false;
}
@Override
public User findByOpenid(String openid) {
return findUnique(FIND_BY_OPENID,new Hints(),openid);
}
}
......@@ -51,7 +51,7 @@ public class User {
private String email; //邮箱
private String tel; //固定电话
private String qq;
private String weixin; //微信号
private String openid; //微信openid
private Integer donateBloodCount; //无偿献血次数
private String bloodType; //血型
private Integer height; //身高
......@@ -246,13 +246,16 @@ public class User {
public void setQq(String qq) {
this.qq = qq;
}
public String getWeixin() {
return weixin;
}
public void setWeixin(String weixin) {
this.weixin = weixin;
}
public Integer getDonateBloodCount() {
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public Integer getDonateBloodCount() {
return donateBloodCount;
}
public void setDonateBloodCount(Integer donateBloodCount) {
......
package com.qiankun.service;
import org.dom4j.util.UserDataDocumentFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -54,4 +55,7 @@ public class UserService {
public Boolean validatePwd(String id, String password) {
return userDao.validatePwd(id, MD5.digest(password));
}
public User findByOpenid(String openid){
return userDao.findByOpenid(openid);
}
}
......@@ -10,4 +10,9 @@ rainbowplan.appid=wxd097672957e48ba8
rainbowplan.secret=6500d648cc5715f8829dab993de746f3
rainbowplan.token=
rainbowplan.aesKey=
rainbowplan.msgDataFormat: JSON
\ No newline at end of file
rainbowplan.msgDataFormat=JSON
tjmdp.appid=wx77f58984e50cbc08
tjmdp.secret=6e6e00e5c01216c2464a8771cb9bdfca
tjmdp.token=
tjmdp.aesKey=
tjmdp.msgDataFormat=JSON
\ 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