From bf25ec2de96db592c9459e878aa5e69c295ebffc Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Sat, 10 Oct 2020 18:40:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=89=AB=E4=B8=80=E6=89=ABur?= =?UTF-8?q?l=E6=8E=A5=E5=8F=A3=E7=BC=96=E5=86=99=EF=BC=8C=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../target/classes/bootstrap.properties | 19 ---- .../target/classes/logback-spring.xml | 47 -------- .../mapper/crmsauth/CustomerLoginMapper.xml | 10 -- .../DqFinancialCrmsAuthApplicationTests.class | Bin 586 -> 0 bytes .../financial/hrauth/config/WeChatConfig.java | 61 ++++++++++ .../controller/UserLoginController.java | 54 +++++++++ .../financial/hrauth/dao/UserLoginDao.java | 1 + .../financial/hrauth/service/UserService.java | 12 ++ .../hrauth/service/impl/UserServiceImpl.java | 76 +++++++++++++ .../financial/hrauth/util/HttpUtils.java | 106 ++++++++++++++++++ .../src/main/resources/bootstrap.properties | 5 + .../mapper/hrmsauth/UserLoginMapper.xml | 3 + .../src/main/resources/jwt.properties | 3 +- 13 files changed, 320 insertions(+), 77 deletions(-) delete mode 100644 dq-financial-crms-auth/target/classes/bootstrap.properties delete mode 100644 dq-financial-crms-auth/target/classes/logback-spring.xml delete mode 100644 dq-financial-crms-auth/target/classes/mapper/crmsauth/CustomerLoginMapper.xml delete mode 100644 dq-financial-crms-auth/target/test-classes/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.class create mode 100644 dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/WeChatConfig.java create mode 100644 dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserService.java create mode 100644 dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java create mode 100644 dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/HttpUtils.java diff --git a/dq-financial-crms-auth/target/classes/bootstrap.properties b/dq-financial-crms-auth/target/classes/bootstrap.properties deleted file mode 100644 index 160ddf8b..00000000 --- a/dq-financial-crms-auth/target/classes/bootstrap.properties +++ /dev/null @@ -1,19 +0,0 @@ - -#服务名称 -spring.application.name=dq-financial-crms -#配置中心地址 -spring.cloud.nacos.config.server-addr=192.168.31.142:8848 -spring.cloud.nacos.config.namespace=37d72d30-3178-4173-8b5e-269a23355ed9 -#spring.cloud.nacos.config.group=prod - -spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml -spring.cloud.nacos.config.ext-config[0].group=dev -spring.cloud.nacos.config.ext-config[0].refresh=true - -spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml -spring.cloud.nacos.config.ext-config[1].group=dev -spring.cloud.nacos.config.ext-config[1].refresh=true - -spring.cloud.nacos.config.ext-config[2].data-id=other.yml -spring.cloud.nacos.config.ext-config[2].group=dev -spring.cloud.nacos.config.ext-config[2].refresh=true \ No newline at end of file diff --git a/dq-financial-crms-auth/target/classes/logback-spring.xml b/dq-financial-crms-auth/target/classes/logback-spring.xml deleted file mode 100644 index 9d44c6c1..00000000 --- a/dq-financial-crms-auth/target/classes/logback-spring.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - utf8 - - - - - - - - ${LOG_HOME}/crms_auth.%d{yyyy-MM-dd}.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - 0 - - 512 - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-financial-crms-auth/target/classes/mapper/crmsauth/CustomerLoginMapper.xml b/dq-financial-crms-auth/target/classes/mapper/crmsauth/CustomerLoginMapper.xml deleted file mode 100644 index ac1cc76d..00000000 --- a/dq-financial-crms-auth/target/classes/mapper/crmsauth/CustomerLoginMapper.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/dq-financial-crms-auth/target/test-classes/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.class b/dq-financial-crms-auth/target/test-classes/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.class deleted file mode 100644 index d5a57e61ad9c115d1177e58d0e9e5b672bc35f11..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 586 zcmbtRO-lnY5S?s4R@>Fq>cyMKs$eeSMN!sDPm6*ry=T+3P2Ek}Y*zhSo&*p60DqJ? zNh=6m1Ov%rUgo`dNj^T`-T~kg_8L%uoe(-9>=LM7NG0thflBvqM4;N!V?m&mNF{E| zJQZfh(hQMKqB+Y(%t)87!K$6ff*}`qEkL{-NW^oINrEXI`pU7<4`{EEiAOJkV5YOD!tXwJAFA71xOSh7nYuM&Rn7 z*T$?z;P { UserEntity login(LoginRequest loginRequest); UserEntity selectByPhoneAccount(String phoneAccount); + UserEntity findByOpenid(String openId); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserService.java new file mode 100644 index 00000000..43e4c699 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserService.java @@ -0,0 +1,12 @@ +package com.daqing.financial.hrauth.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.daqing.framework.domain.hrms.UserEntity; + +/** + * @auther River + * @date 2020/9/22 15:00 + */ +public interface UserService extends IService { + UserEntity saveWeChatUser(String code); +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..133f5e41 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserServiceImpl.java @@ -0,0 +1,76 @@ +package com.daqing.financial.hrauth.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.daqing.financial.hrauth.config.WeChatConfig; +import com.daqing.financial.hrauth.dao.UserLoginDao; +import com.daqing.financial.hrauth.service.UserService; +import com.daqing.financial.hrauth.util.HttpUtils; +import com.daqing.framework.domain.hrms.UserEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.io.UnsupportedEncodingException; +import java.util.Date; +import java.util.Map; + +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + + @Autowired + private WeChatConfig weChatConfig; + + @Resource + private UserLoginDao userMapper; + + @Override + public UserEntity saveWeChatUser(String code) { + + String accessTokenUrl = String.format(weChatConfig.getOPEN_ACCESS_TOKEN_URL(),weChatConfig.getOpenAppid(),weChatConfig.getOpenAppsecret(),code); + + //鑾峰彇access_token + Map baseMap = HttpUtils.doGet(accessTokenUrl); + + if(baseMap == null || baseMap.isEmpty()){ return null; } + String accessToken = (String)baseMap.get("access_token"); + String openId = (String) baseMap.get("openid"); + + UserEntity dbUser = userMapper.findByOpenid(openId); + + if(dbUser!=null) { //鏇存柊鐢ㄦ埛锛岀洿鎺ヨ繑鍥 + return dbUser; + } + + //鑾峰彇鐢ㄦ埛鍩烘湰淇℃伅 + String userInfoUrl = String.format(weChatConfig.getOPEN_USER_INFO_URL(),accessToken,openId); + Map baseUserMap = HttpUtils.doGet(userInfoUrl); + + if(baseUserMap == null || baseUserMap.isEmpty()){ + return null; + } +/* String nickname = (String)baseUserMap.get("nickname"); + + Double sexTemp = (Double) baseUserMap.get("sex"); + int sex = sexTemp.intValue(); + String province = (String)baseUserMap.get("province"); + String city = (String)baseUserMap.get("city"); + String country = (String)baseUserMap.get("country"); + String headimgurl = (String)baseUserMap.get("headimgurl"); + StringBuilder sb = new StringBuilder(country).append("||").append(province).append("||").append(city); + String finalAddress = sb.toString(); + try { + //瑙e喅涔辩爜 + nickname = new String(nickname.getBytes("ISO-8859-1"), "UTF-8"); + finalAddress = new String(finalAddress.getBytes("ISO-8859-1"), "UTF-8"); + + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + }*/ + + UserEntity user = new UserEntity(); + user.setWechatId(openId); + user.setCreateTime(new Date()); + userMapper.insert(user); + return user; + } +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/HttpUtils.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/HttpUtils.java new file mode 100644 index 00000000..e75e62fb --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/HttpUtils.java @@ -0,0 +1,106 @@ +package com.daqing.financial.hrauth.util; + +import com.google.gson.Gson; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import java.util.HashMap; +import java.util.Map; + +/** + * 灏佽http get post + */ +public class HttpUtils { + + private static final Gson gson = new Gson(); + + /** + * get鏂规硶 + * @param url + * @return + */ + public static Map doGet(String url){ + + Map map = new HashMap<>(); + CloseableHttpClient httpClient = HttpClients.createDefault(); + + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000) //杩炴帴瓒呮椂 + .setConnectionRequestTimeout(5000)//璇锋眰瓒呮椂 + .setSocketTimeout(5000) + .setRedirectsEnabled(true) //鍏佽鑷姩閲嶅畾鍚 + .build(); + + HttpGet httpGet = new HttpGet(url); + httpGet.setConfig(requestConfig); + + try{ + HttpResponse httpResponse = httpClient.execute(httpGet); + if(httpResponse.getStatusLine().getStatusCode() == 200){ + + String jsonResult = EntityUtils.toString( httpResponse.getEntity()); + map = gson.fromJson(jsonResult,map.getClass()); + } + + }catch (Exception e){ + e.printStackTrace(); + }finally { + try { + httpClient.close(); + }catch (Exception e){ + e.printStackTrace(); + } + } + return map; + } + + /** + * 灏佽post + * @return + */ + public static String doPost(String url, String data,int timeout){ + CloseableHttpClient httpClient = HttpClients.createDefault(); + //瓒呮椂璁剧疆 + + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout) //杩炴帴瓒呮椂 + .setConnectionRequestTimeout(timeout)//璇锋眰瓒呮椂 + .setSocketTimeout(timeout) + .setRedirectsEnabled(true) //鍏佽鑷姩閲嶅畾鍚 + .build(); + + HttpPost httpPost = new HttpPost(url); + httpPost.setConfig(requestConfig); + httpPost.addHeader("Content-Type","text/html; chartset=UTF-8"); + + if(data != null && data instanceof String){ //浣跨敤瀛楃涓蹭紶鍙 + StringEntity stringEntity = new StringEntity(data,"UTF-8"); + httpPost.setEntity(stringEntity); + } + + try{ + CloseableHttpResponse httpResponse = httpClient.execute(httpPost); + HttpEntity httpEntity = httpResponse.getEntity(); + if(httpResponse.getStatusLine().getStatusCode() == 200){ + String result = EntityUtils.toString(httpEntity); + return result; + } + + }catch (Exception e){ + e.printStackTrace(); + }finally { + try{ + httpClient.close(); + }catch (Exception e){ + e.printStackTrace(); + } + } + return null; + } + +} \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/main/resources/bootstrap.properties b/dq-financial-hrms-auth/src/main/resources/bootstrap.properties index b2c4518d..caddf3ab 100644 --- a/dq-financial-hrms-auth/src/main/resources/bootstrap.properties +++ b/dq-financial-hrms-auth/src/main/resources/bootstrap.properties @@ -27,6 +27,11 @@ spring.redis.jedis.pool.max-wait=-1 spring.redis.jedis.pool.max-idle=8 spring.redis.jedis.pool.min-idle=0 +#寰俊寮鏀惧钩鍙伴厤缃 +wxopen.appid=wx3b7bca679da34921 +wxopen.appsecret=c8de113c18052b4e2173d913511e486d +#鍥炶皟鍦板潃 +wxopen.redirect_url=http://www.occupationlab.com/apiHrmsAuth/hrms/auth/userlogin/user/callback # 姝e紡鐜锛坧rod锛 #spring.application.name=dq-financial-hrms-auth diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml index fd2d7237..e813de8a 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml @@ -37,5 +37,8 @@ + \ No newline at end of file diff --git a/dq-govern-gateway/src/main/resources/jwt.properties b/dq-govern-gateway/src/main/resources/jwt.properties index 6bef2a95..5ffed5bc 100644 --- a/dq-govern-gateway/src/main/resources/jwt.properties +++ b/dq-govern-gateway/src/main/resources/jwt.properties @@ -4,4 +4,5 @@ jwt.ignoreUrlList=/apiHrmsAuth/hrms/auth/userlogin/getBackPwd,\ /api-crms/sweagger-ui.html,\ /api-crms/crms/customer/excelTemplate,\ /api-crms/crms/customer/excelExport,\ - /api-crms/crms/customer/excelImport \ No newline at end of file + /api-crms/crms/customer/excelImport,\ + /apiHrmsAuth/hrms/auth/userlogin/wxLoginUrl \ No newline at end of file