|
|
@@ -1,12 +1,18 @@
|
|
|
package com.zhongzheng.framework.web.service;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zhongzheng.common.core.bo.WxLoginResultBo;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
|
|
|
+import com.zhongzheng.common.utils.AES;
|
|
|
+import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
|
+import com.zhongzheng.modules.wx.bo.WxLoginBody;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -39,7 +45,8 @@ public class WxLoginService
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
|
- public String login(String unionId) {
|
|
|
+ public String login(WxLoginBody loginBody) {
|
|
|
+ String unionId = getWxUnionId(loginBody.getCode());
|
|
|
User user = iUserService.queryByUnionId(unionId);
|
|
|
if(user==null){
|
|
|
throw new CustomException("unionId不存在");
|
|
|
@@ -49,9 +56,41 @@ public class WxLoginService
|
|
|
return wxTokenService.createToken(loginUser);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 小程序注册
|
|
|
+ * @param openId
|
|
|
+ * @param unionId
|
|
|
+ * @param tel
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String register_small(String openId,String unionId,String tel) {
|
|
|
+ UserAddBo bo = new UserAddBo();
|
|
|
+ bo.setOpenId(openId);
|
|
|
+ bo.setUnionId(unionId);
|
|
|
+ bo.setTelphone(tel);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public String getWxUnionId(String code) {
|
|
|
String url = String.format(wxAuthUrl, appid, appsrcret, code);
|
|
|
WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public void obtainWxPhone(String iv, String encryptedData,String session_key){
|
|
|
+ String userInfo = null;
|
|
|
+ JSONObject userInfoJSON = null;
|
|
|
+ try {
|
|
|
+ byte[] resultByte = AES.decrypt(Base64.decodeBase64(encryptedData),
|
|
|
+ Base64.decodeBase64(session_key),
|
|
|
+ Base64.decodeBase64(iv));
|
|
|
+
|
|
|
+ userInfo = new String(resultByte, "UTF-8");
|
|
|
+ System.out.println("userInfo:" + userInfo);
|
|
|
+ userInfoJSON = JSON.parseObject(userInfo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|