Commit 038e3099 authored by liuyang's avatar liuyang

添加志原者服务后台接口

parent 79ae949f
...@@ -29,6 +29,13 @@ public class WxMaProperties { ...@@ -29,6 +29,13 @@ public class WxMaProperties {
config.setSecret(rb.getString("rainbowplan.secret")); config.setSecret(rb.getString("rainbowplan.secret"));
configs = Lists.newArrayList(); configs = Lists.newArrayList();
configs.add(config); 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 { 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; package com.qiankun.controller.rainbowplan;
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.common.base.Strings; import com.google.common.base.Strings;
...@@ -296,6 +297,21 @@ public class RainbowPlanController { ...@@ -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) @Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/loadResource",method = RequestMethod.GET) @RequestMapping(value = "/loadResource",method = RequestMethod.GET)
......
...@@ -17,4 +17,5 @@ public interface UserDao extends IDao<User, String> { ...@@ -17,4 +17,5 @@ public interface UserDao extends IDao<User, String> {
Boolean validateUserExistByUserName(String userName); Boolean validateUserExistByUserName(String userName);
User findByOpenid(String openid);
} }
...@@ -26,6 +26,7 @@ public class UserDaoImpl extends AbsDao<User, String> implements UserDao { ...@@ -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_USERNAME = " from User where userName = ?";
private static final String VALIDATE_PWD = " from User where id = ? and pwd = ? and isRemove=false"; 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 @Override
public Boolean validateUserExistByPaperId(String paperId) { public Boolean validateUserExistByPaperId(String paperId) {
...@@ -106,4 +107,9 @@ public class UserDaoImpl extends AbsDao<User, String> implements UserDao { ...@@ -106,4 +107,9 @@ public class UserDaoImpl extends AbsDao<User, String> implements UserDao {
return false; return false;
} }
@Override
public User findByOpenid(String openid) {
return findUnique(FIND_BY_OPENID,new Hints(),openid);
}
} }
...@@ -51,7 +51,7 @@ public class User { ...@@ -51,7 +51,7 @@ public class User {
private String email; //电话 private String email; //电话
private String tel; //固定电话 private String tel; //固定电话
private String qq; private String qq;
private String weixin; //微信号 private String openid; //微信openid
private Integer donateBloodCount; //无偿献血次数 private Integer donateBloodCount; //无偿献血次数
private String bloodType; //血型 private String bloodType; //血型
private Integer height; //身高 private Integer height; //身高
...@@ -245,13 +245,16 @@ public class User { ...@@ -245,13 +245,16 @@ public class User {
public void setQq(String qq) { public void setQq(String qq) {
this.qq = qq; this.qq = qq;
} }
public String getWeixin() {
return weixin; public String getOpenid() {
} return openid;
public void setWeixin(String weixin) { }
this.weixin = weixin;
} public void setOpenid(String openid) {
public Integer getDonateBloodCount() { this.openid = openid;
}
public Integer getDonateBloodCount() {
return donateBloodCount; return donateBloodCount;
} }
public void setDonateBloodCount(Integer donateBloodCount) { public void setDonateBloodCount(Integer donateBloodCount) {
......
package com.qiankun.service; package com.qiankun.service;
import org.dom4j.util.UserDataDocumentFactory;
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 org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -54,4 +55,7 @@ public class UserService { ...@@ -54,4 +55,7 @@ public class UserService {
public Boolean validatePwd(String id, String password) { public Boolean validatePwd(String id, String password) {
return userDao.validatePwd(id, MD5.digest(password)); return userDao.validatePwd(id, MD5.digest(password));
} }
public User findByOpenid(String openid){
return userDao.findByOpenid(openid);
}
} }
...@@ -10,4 +10,9 @@ rainbowplan.appid=wxd097672957e48ba8 ...@@ -10,4 +10,9 @@ rainbowplan.appid=wxd097672957e48ba8
rainbowplan.secret=6500d648cc5715f8829dab993de746f3 rainbowplan.secret=6500d648cc5715f8829dab993de746f3
rainbowplan.token= rainbowplan.token=
rainbowplan.aesKey= rainbowplan.aesKey=
rainbowplan.msgDataFormat: JSON rainbowplan.msgDataFormat=JSON
\ No newline at end of file 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