| | |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | IPageData pd = PageData.newInstance().builder("","", postInfo,"","","",""); |
| | | IPageData pd = PageData.newInstance().builder("", "", postInfo, |
| | | "", "", "", "", |
| | | request.getHeader("APP_ID")); |
| | | |
| | | return wxLoginSMOImpl.doLogin(pd); |
| | | return wxLoginSMOImpl.doLogin(pd); |
| | | |
| | | //login first |
| | | /*User user = userService.queryByOpenid(openId); |
| New file |
| | |
| | | package com.java110.app.smo; |
| | | |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.core.component.AbstractComponentSMO; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.utils.constant.CommonConstant; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.http.*; |
| | | import org.springframework.web.client.HttpStatusCodeException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | public abstract class AppAbstractComponentSMO extends AbstractComponentSMO { |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(AppAbstractComponentSMO.class); |
| | | |
| | | |
| | | /** |
| | | * 调用中心服务 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | protected ResponseEntity<String> callCenterService(RestTemplate restTemplate, IPageData pd, String param, String url, HttpMethod httpMethod) { |
| | | |
| | | Assert.notNull(pd.getAppId(), "请求头中未包含应用信息"); |
| | | ResponseEntity<String> responseEntity = null; |
| | | HttpHeaders header = new HttpHeaders(); |
| | | header.add(CommonConstant.HTTP_APP_ID.toLowerCase(), pd.getAppId()); |
| | | header.add(CommonConstant.HTTP_USER_ID.toLowerCase(), StringUtil.isEmpty(pd.getUserId()) ? CommonConstant.ORDER_DEFAULT_USER_ID : pd.getUserId()); |
| | | header.add(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), pd.getTransactionId()); |
| | | header.add(CommonConstant.HTTP_REQ_TIME.toLowerCase(), pd.getRequestTime()); |
| | | header.add(CommonConstant.HTTP_SIGN.toLowerCase(), ""); |
| | | HttpEntity<String> httpEntity = new HttpEntity<String>(param, header); |
| | | //logger.debug("请求中心服务信息,{}", httpEntity); |
| | | try { |
| | | responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class); |
| | | } catch (HttpStatusCodeException e) { //这里spring 框架 在4XX 或 5XX 时抛出 HttpServerErrorException 异常,需要重新封装一下 |
| | | responseEntity = new ResponseEntity<String>("请求下游系统异常," + e.getResponseBodyAsString(), e.getStatusCode()); |
| | | } catch (Exception e) { |
| | | responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } finally { |
| | | logger.debug("请求地址为,{} 请求中心服务信息,{},中心服务返回信息,{}", url, httpEntity, responseEntity); |
| | | return responseEntity; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.app.properties.WechatAuthProperties; |
| | | import com.java110.app.smo.AppAbstractComponentSMO; |
| | | import com.java110.app.smo.wxLogin.IWxLoginSMO; |
| | | import com.java110.core.component.AbstractComponentSMO; |
| | | import com.java110.core.context.IPageData; |
| | |
| | | * wx登录 |
| | | */ |
| | | @Service("wxLoginSMOImpl") |
| | | public class WxLoginSMOImpl extends AbstractComponentSMO implements IWxLoginSMO { |
| | | public class WxLoginSMOImpl extends AppAbstractComponentSMO implements IWxLoginSMO { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(WxLoginSMOImpl.class); |
| | | |
| | |
| | | */ |
| | | String getUserId(); |
| | | |
| | | String getAppId(); |
| | | |
| | | /** |
| | | * 获取交易流水 |
| | | * @return 交易流水 |
| | |
| | | * @return IPageData对象 |
| | | * @throws IllegalArgumentException 参数错误异常 |
| | | */ |
| | | IPageData builder(String userId, String token, String reqData, String componentCode, String componentMethod, String url, String sessionId) |
| | | IPageData builder(String userId, |
| | | String token, |
| | | String reqData, |
| | | String componentCode, |
| | | String componentMethod, |
| | | String url, |
| | | String sessionId, |
| | | String appId) |
| | | throws IllegalArgumentException; |
| | | |
| | | IPageData builder(String userId, |
| | | String token, |
| | | String reqData, |
| | | String componentCode, |
| | | String componentMethod, |
| | | String url, |
| | | String sessionId) |
| | | throws IllegalArgumentException; |
| | | |
| | | } |
| | |
| | | * 页面请求数据封装 |
| | | * Created by wuxw on 2018/5/2. |
| | | */ |
| | | public class PageData implements IPageData,Serializable { |
| | | public class PageData implements IPageData, Serializable { |
| | | |
| | | |
| | | |
| | | public PageData(){ |
| | | public PageData() { |
| | | |
| | | this.setTransactionId(UUID.randomUUID().toString()); |
| | | } |
| | | |
| | | |
| | | private String userId ; |
| | | private String userId; |
| | | |
| | | private String appId; |
| | | |
| | | //会话ID |
| | | private String sessionId; |
| | |
| | | |
| | | /** |
| | | * 初始化 PageData |
| | | * |
| | | * @return |
| | | */ |
| | | public static IPageData newInstance(){ |
| | | public static IPageData newInstance() { |
| | | return new PageData(); |
| | | } |
| | | |
| | | public IPageData builder(Map param) throws IllegalArgumentException{ |
| | | public IPageData builder(Map param) throws IllegalArgumentException { |
| | | JSONObject reqJson = null; |
| | | |
| | | return this; |
| | | } |
| | | |
| | | public IPageData builder(String userId,String token,String reqData,String componentCode,String componentMethod,String url,String sessionId) |
| | | throws IllegalArgumentException{ |
| | | public IPageData builder(String userId, |
| | | String token, |
| | | String reqData, |
| | | String componentCode, |
| | | String componentMethod, |
| | | String url, |
| | | String sessionId) { |
| | | return builder(userId, |
| | | token, |
| | | reqData, |
| | | componentCode, |
| | | componentMethod, |
| | | url, |
| | | sessionId, |
| | | ""); |
| | | } |
| | | |
| | | public IPageData builder(String userId, |
| | | String token, |
| | | String reqData, |
| | | String componentCode, |
| | | String componentMethod, |
| | | String url, |
| | | String sessionId, |
| | | String appId) |
| | | throws IllegalArgumentException { |
| | | this.setComponentCode(componentCode); |
| | | this.setComponentMethod(componentMethod); |
| | | this.setReqData(reqData); |
| | |
| | | this.setToken(token); |
| | | this.setUrl(url); |
| | | this.setSessionId(sessionId); |
| | | this.setAppId(appId); |
| | | |
| | | return this; |
| | | } |
| | | |
| | | public String toString(){ |
| | | public String toString() { |
| | | return JSONObject.toJSONString(this); |
| | | } |
| | | |
| | | @Override |
| | | public String getAppId() { |
| | | return appId; |
| | | } |
| | | |
| | | public void setAppId(String appId) { |
| | | this.appId = appId; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getToken(), |
| | | reqData, pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId()); |
| | | reqData, pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId(),""); |
| | | return newPd; |
| | | } |
| | | |
| | |
| | | IPageData pd = null; |
| | | String reqData = ""; |
| | | String userId = ""; |
| | | String appId = ""; |
| | | String sessionId = request.getSession().getId(); |
| | | appId = request.getHeader("APP_ID"); |
| | | if ("POST,PUT".contains(request.getMethod())) { |
| | | InputStream in = request.getInputStream(); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); |
| | |
| | | componentCode = urls[4]; |
| | | } |
| | | } |
| | | |
| | | pd = PageData.newInstance().builder(userId, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId); |
| | | pd = PageData.newInstance().builder(userId, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId, appId); |
| | | request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, pd); |
| | | |
| | | } |
| | |
| | | */ |
| | | public final static String HC_WEB_APP_ID = "8000418004"; |
| | | |
| | | /** |
| | | * 小区管理系统web端 APP_ID |
| | | */ |
| | | public final static String HC_APP_FRONT_APP_ID = "8000418004"; |
| | | |
| | | |
| | | |
| | | } |