Commit fa952562 by Water Wang

optimize

parent 150d5052
...@@ -3,6 +3,7 @@ package com.yd.api.practitioner.service.impl; ...@@ -3,6 +3,7 @@ package com.yd.api.practitioner.service.impl;
import com.yd.api.customer.service.CustomerService; import com.yd.api.customer.service.CustomerService;
import com.yd.api.customer.vo.register.RegisterRequestVO; import com.yd.api.customer.vo.register.RegisterRequestVO;
import com.yd.api.customer.vo.register.RegisterResponseVO; import com.yd.api.customer.vo.register.RegisterResponseVO;
import com.yd.api.practitioner.vo.login.PractitionerLoginBasicInfo;
import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO; import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO;
import com.yd.api.practitioner.vo.login.PractitionerLoginResponseVO; import com.yd.api.practitioner.vo.login.PractitionerLoginResponseVO;
import com.yd.api.practitioner.vo.media.MediaGetReqVO; import com.yd.api.practitioner.vo.media.MediaGetReqVO;
...@@ -20,6 +21,7 @@ import com.yd.dal.service.customer.*; ...@@ -20,6 +21,7 @@ import com.yd.dal.service.customer.*;
import com.yd.dal.service.meta.MdCodeDALService; import com.yd.dal.service.meta.MdCodeDALService;
import com.yd.rmi.ali.oss.service.OssService; import com.yd.rmi.ali.oss.service.OssService;
import com.yd.rmi.tencent.wechat.service.WechatService; import com.yd.rmi.tencent.wechat.service.WechatService;
import com.yd.rmi.tencent.wechat.vo.WeChatInfoByENV;
import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest; import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.token.TokenRequest; import com.yd.rmi.tencent.wechatinterf.pojo.token.TokenRequest;
import com.yd.util.CommonUtil; import com.yd.util.CommonUtil;
...@@ -36,10 +38,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -36,10 +38,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.ByteArrayOutputStream; import java.net.URLEncoder;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
...@@ -67,6 +67,8 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service. ...@@ -67,6 +67,8 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
private AclPractitionerPotentialDALService aclPractitionerPotentialDALService; private AclPractitionerPotentialDALService aclPractitionerPotentialDALService;
@Autowired @Autowired
private AclPractitionerPotentialAssignedTrackDALService aclPractitionerPotentialAssignedTrackDALService; private AclPractitionerPotentialAssignedTrackDALService aclPractitionerPotentialAssignedTrackDALService;
@Autowired
private AclCustomerDALService aclCustomerDALService;
@Override @Override
...@@ -93,7 +95,8 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service. ...@@ -93,7 +95,8 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
if(28L == practitionerType || isSpecial){//只有寿险的经纪人和注册为经纪人的员工才能登录 if(28L == practitionerType || isSpecial){//只有寿险的经纪人和注册为经纪人的员工才能登录
Long practitionerId = practitionerInfo.getPractitionerId(); Long practitionerId = practitionerInfo.getPractitionerId();
Long customerId = practitionerInfo.getCustomerId(); Long customerId = practitionerInfo.getCustomerId();
com.yd.api.practitioner.vo.login.PractitionerBasicInfo basicInfo = new com.yd.api.practitioner.vo.login.PractitionerBasicInfo(); AclCustomer customer = aclCustomerDALService.findById(customerId);
PractitionerLoginBasicInfo basicInfo = new PractitionerLoginBasicInfo();
BeanUtils.copyProperties(practitionerInfo,basicInfo); BeanUtils.copyProperties(practitionerInfo,basicInfo);
//获取头像 //获取头像
Integer targetType = 1, targetUseFor = 1; Integer targetType = 1, targetUseFor = 1;
...@@ -114,6 +117,7 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service. ...@@ -114,6 +117,7 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
int logTimes = (customerLogList.isEmpty()) ? 0 : customerLogList.size(); int logTimes = (customerLogList.isEmpty()) ? 0 : customerLogList.size();
//保存用户的登录记录 //保存用户的登录记录
aclCustomerLogDALService.saveCustomerLog(customerId,2); aclCustomerLogDALService.saveCustomerLog(customerId,2);
getOpenIdUrl(responseVO,customer);
responseVO.setCustomerId(customerId); responseVO.setCustomerId(customerId);
responseVO.setPractitionerId(practitionerId); responseVO.setPractitionerId(practitionerId);
responseVO.setPractitionerBasicInfo(basicInfo); responseVO.setPractitionerBasicInfo(basicInfo);
...@@ -126,6 +130,30 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service. ...@@ -126,6 +130,30 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
return responseVO; return responseVO;
} }
private void getOpenIdUrl(PractitionerLoginResponseVO responseVO, AclCustomer customer) {
String openId = customer.getYdWechatOpenid();
if(Strings.isNullOrEmpty(openId)) {
WeChatInfoByENV weChatInfo = wechatService.getWeChatInfoByENV("YDBJ", false);
String appId = weChatInfo.getAppId(), secret = weChatInfo.getSecret();
if (!Strings.isNullOrEmpty(appId) && !Strings.isNullOrEmpty(secret)) {
try {
String info = appId+","+customer.getId();
String redirectUri = mdCodeDALService.findCodeByType("FilePathPrefix")+"api/getOpenId?info=" + info;
redirectUri = URLEncoder.encode(redirectUri, "UTF-8");
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
+ "appid=" + appId
+ "&redirect_uri=" + redirectUri
+ "&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
System.out.println(">>>>>url>>>>>>>:" + url);
responseVO.setGetOpenIdUrl(url);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
@Override @Override
public PractitionerRankResponseVO practitionerRank(PractitionerRankRequestVO requestVO) { public PractitionerRankResponseVO practitionerRank(PractitionerRankRequestVO requestVO) {
PractitionerRankResponseVO responseVO = new PractitionerRankResponseVO(); PractitionerRankResponseVO responseVO = new PractitionerRankResponseVO();
......
package com.yd.api.practitioner.vo.login; package com.yd.api.practitioner.vo.login;
public class PractitionerBasicInfo { public class PractitionerLoginBasicInfo {
private String name;//姓名 private String name;//姓名
private String headImagePath;//头像 private String headImagePath;//头像
private String levelCode;//级别code private String levelCode;//级别code
......
...@@ -7,7 +7,8 @@ public class PractitionerLoginResponseVO { ...@@ -7,7 +7,8 @@ public class PractitionerLoginResponseVO {
private Long customerId; private Long customerId;
private Long practitionerId; private Long practitionerId;
private Integer loginTimes; private Integer loginTimes;
private PractitionerBasicInfo practitionerBasicInfo; private String getOpenIdUrl;
private PractitionerLoginBasicInfo practitionerBasicInfo;
private CommonResult commonResult; private CommonResult commonResult;
public Long getCustomerId() { public Long getCustomerId() {
...@@ -34,14 +35,22 @@ public class PractitionerLoginResponseVO { ...@@ -34,14 +35,22 @@ public class PractitionerLoginResponseVO {
this.loginTimes = loginTimes; this.loginTimes = loginTimes;
} }
public PractitionerBasicInfo getPractitionerBasicInfo() { public PractitionerLoginBasicInfo getPractitionerBasicInfo() {
return practitionerBasicInfo; return practitionerBasicInfo;
} }
public void setPractitionerBasicInfo(PractitionerBasicInfo practitionerBasicInfo) { public void setPractitionerBasicInfo(PractitionerLoginBasicInfo practitionerBasicInfo) {
this.practitionerBasicInfo = practitionerBasicInfo; this.practitionerBasicInfo = practitionerBasicInfo;
} }
public String getGetOpenIdUrl() {
return getOpenIdUrl;
}
public void setGetOpenIdUrl(String getOpenIdUrl) {
this.getOpenIdUrl = getOpenIdUrl;
}
public CommonResult getCommonResult() { public CommonResult getCommonResult() {
return commonResult; return commonResult;
} }
......
...@@ -281,6 +281,7 @@ public class AclCustomer implements Serializable { ...@@ -281,6 +281,7 @@ public class AclCustomer implements Serializable {
* 年龄 * 年龄
*/ */
private Long age; private Long age;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -19,4 +19,8 @@ public interface TenInterfRecordMapper { ...@@ -19,4 +19,8 @@ public interface TenInterfRecordMapper {
int updateByPrimaryKey(TenInterfRecord record); int updateByPrimaryKey(TenInterfRecord record);
List<TenInterfRecord> findByTenInterfRecordOrderBy(@Param("info") TenInterfRecord tencentInterfRecord, @Param("orderBy")String orderBy); List<TenInterfRecord> findByTenInterfRecordOrderBy(@Param("info") TenInterfRecord tencentInterfRecord, @Param("orderBy")String orderBy);
List<TenInterfRecord> findByAppIdAndGrantType(@Param("appId")String appId, @Param("grantType")String grantType, @Param("type")String type);
List<TenInterfRecord> findByAccessTokenAndIType(@Param("accessToken")String accessToken, @Param("pType")String pType,@Param("type")String type);
} }
\ No newline at end of file
...@@ -21,4 +21,12 @@ public interface AclCustomerDALService { ...@@ -21,4 +21,12 @@ public interface AclCustomerDALService {
* @return * @return
*/ */
void save(AclCustomer aclCustomer); void save(AclCustomer aclCustomer);
/**
* 获取用户信息
* @param customerId
* @return
*/
AclCustomer findById(Long customerId);
} }
...@@ -22,4 +22,9 @@ public class AclCustomerDALServiceImpl implements AclCustomerDALService { ...@@ -22,4 +22,9 @@ public class AclCustomerDALServiceImpl implements AclCustomerDALService {
public void save(AclCustomer aclCustomer) { public void save(AclCustomer aclCustomer) {
aclCustomerMapper.insert(aclCustomer); aclCustomerMapper.insert(aclCustomer);
} }
@Override
public AclCustomer findById(Long customerId) {
return aclCustomerMapper.selectByPrimaryKey(customerId);
}
} }
...@@ -23,4 +23,14 @@ public class TenInterfRecordDALServiceImpl implements TenInterfRecordDALService ...@@ -23,4 +23,14 @@ public class TenInterfRecordDALServiceImpl implements TenInterfRecordDALService
public List<TenInterfRecord> findByTenInterfRecordOrderBy(TenInterfRecord tencentInterfRecord, String orderBy) { public List<TenInterfRecord> findByTenInterfRecordOrderBy(TenInterfRecord tencentInterfRecord, String orderBy) {
return tenInterfRecordMapper.findByTenInterfRecordOrderBy(tencentInterfRecord, orderBy); return tenInterfRecordMapper.findByTenInterfRecordOrderBy(tencentInterfRecord, orderBy);
} }
@Override
public List<TenInterfRecord> findByAppIdAndGrantType(String appId, String grantType) {
return tenInterfRecordMapper.findByAppIdAndGrantType(appId,grantType,"TOKEN");
}
@Override
public List<TenInterfRecord> findByAccessTokenAndIType(String accessToken, String pType) {
return tenInterfRecordMapper.findByAccessTokenAndIType(accessToken,pType,"TICKET");
}
} }
...@@ -8,4 +8,8 @@ public interface TenInterfRecordDALService { ...@@ -8,4 +8,8 @@ public interface TenInterfRecordDALService {
void saveTenInterfRecord(TenInterfRecord tencentInterfRecord); void saveTenInterfRecord(TenInterfRecord tencentInterfRecord);
List<TenInterfRecord> findByTenInterfRecordOrderBy(TenInterfRecord tencentInterfRecord, String orderBy); List<TenInterfRecord> findByTenInterfRecordOrderBy(TenInterfRecord tencentInterfRecord, String orderBy);
List<TenInterfRecord> findByAppIdAndGrantType(String appId, String grantType);
List<TenInterfRecord> findByAccessTokenAndIType(String accessToken, String pType);
} }
package com.yd.rmi.tencent.wechat; package com.yd.rmi.tencent.wechat;
import com.google.common.base.Strings;
import com.yd.api.result.JsonResult; import com.yd.api.result.JsonResult;
import com.yd.dal.entity.customer.AclCustomer;
import com.yd.dal.entity.customer.AclCustomerLog;
import com.yd.dal.service.customer.AclCustomerDALService;
import com.yd.dal.service.customer.AclCustomerLogDALService;
import com.yd.rmi.cache.SystemConfigService; import com.yd.rmi.cache.SystemConfigService;
import com.yd.rmi.tencent.wechat.service.WechatService; import com.yd.rmi.tencent.wechat.service.WechatService;
import com.yd.rmi.tencent.wechat.vo.accesstoken.AccessTokenByCodeRequest;
import com.yd.rmi.tencent.wechat.vo.accesstoken.AccessTokenByCodeResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest; import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.token.TokenRequest; import com.yd.rmi.tencent.wechatinterf.pojo.token.TokenRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.wechatpay.WxConfigRequestVO; import com.yd.rmi.tencent.wechatinterf.pojo.wechatpay.WxConfigRequestVO;
import com.yd.rmi.tencent.wechatinterf.pojo.wechatpay.WxConfigResponseVO; import com.yd.rmi.tencent.wechatinterf.pojo.wechatpay.WxConfigResponseVO;
import com.yd.rmi.tencent.wechatinterf.service.WechatInterfService;
import com.yd.util.SpringContextUtil; import com.yd.util.SpringContextUtil;
import com.yd.util.config.ZHBErrorConfig; import com.yd.util.config.ZHBErrorConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -15,9 +23,15 @@ import org.springframework.web.bind.annotation.CrossOrigin; ...@@ -15,9 +23,15 @@ import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
...@@ -27,6 +41,12 @@ public class WechatController { ...@@ -27,6 +41,12 @@ public class WechatController {
private WechatService wechatService; private WechatService wechatService;
@Autowired @Autowired
private SystemConfigService systemConfigService; private SystemConfigService systemConfigService;
@Autowired
private AclCustomerDALService aclCustomerDALService;
@Autowired
private WechatInterfService wechatInterfService;
@Autowired
private AclCustomerLogDALService aclCustomerLogDALService;
/** /**
* 微信分享时授权 * 微信分享时授权
* @param wxConfigRequestVO * @param wxConfigRequestVO
...@@ -58,4 +78,67 @@ public class WechatController { ...@@ -58,4 +78,67 @@ public class WechatController {
result.setMessage(ZHBErrorConfig.getErrorInfo("800000")); result.setMessage(ZHBErrorConfig.getErrorInfo("800000"));
return result; return result;
} }
/**
* 获取用户的openID
* @param request
* @return
* @throws ServletException
* @throws IOException
*/
@RequestMapping("/getOpenId")
@ResponseBody
public Object getOpenId(HttpServletRequest request) {
String code = request.getParameter("code");
String info = request.getParameter("info");
System.out.println(">>>>>>code>>>>>>" + code);
System.out.println(">>>>>>info>>>>>>" + info);
String jumpUrl = systemConfigService.getSingleConfigValue("YdLifeIndex");//https://mdev.zuihuibi.cn/ydLife/my
if (!Strings.isNullOrEmpty(code) && !Strings.isNullOrEmpty(info)) {
String[] infoArr = info.split(",");
String appId = infoArr[0];
String customerIdStr = infoArr[1];
AccessTokenByCodeResponse accessTokenByCodeResponse = getAccessTokenByCode(code, appId);
if (!Strings.isNullOrEmpty(customerIdStr) && accessTokenByCodeResponse != null) {
Long customerId = Long.parseLong(customerIdStr);
String openId = accessTokenByCodeResponse.getOpenid();
AclCustomer customer = aclCustomerDALService.findById(customerId);
customer.setYdWechatOpenid(openId);
aclCustomerDALService.save(customer);
List<AclCustomerLog> customerLogList = aclCustomerLogDALService.findLogInfoByCustomerId(customerId);
int logTimes = (customerLogList.isEmpty()) ? 0 : customerLogList.size();
jumpUrl = (logTimes < 2) ? systemConfigService.getSingleConfigValue("YdLifeThanksPage") : jumpUrl;
}
}
return new ModelAndView(new RedirectView(jumpUrl));
}
private AccessTokenByCodeResponse getAccessTokenByCode(String code, String appId) {
AccessTokenByCodeResponse accessTokenByCodeResponse = null;
String appIdZHB = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APPID");//最惠比公众账号id
String appIdYD = systemConfigService.getSingleConfigValue("YD-TENCENT_WECHAT_APPID");//银盾公众账号id
String appIdAJB = systemConfigService.getSingleConfigValue("AJB-TENCENT_WECHAT_APPID");//安吉保公众账号id
String appIdYD2 = systemConfigService.getSingleConfigValue("YD2-TENCENT_WECHAT_MINIPRO_APPID");//银盾公众账号id--小程序福利产品
String secret = null;
if(appId.equals(appIdYD)){//银盾
secret = systemConfigService.getSingleConfigValue("YD-TENCENT_WECHAT_APP_SECRET");//第三方用户唯一凭证密钥
}else if(appId.equals(appIdAJB)){//安吉保
secret = systemConfigService.getSingleConfigValue("AJB-TENCENT_WECHAT_APP_SECRET");//第三方用户唯一凭证密钥
}else if(appId.equals(appIdYD2)){//银盾2--福利产品支付
secret = systemConfigService.getSingleConfigValue("YD2-TENCENT_WECHAT_APP_SECRET");//第三方用户唯一凭证密钥
}else if(appId.equals(appIdZHB)){//最惠比--appid
secret = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APP_SECRET");//第三方用户唯一凭证密钥
}
if(!Strings.isNullOrEmpty(secret)){
String grantType = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_ACCESS_TOKEN_GRANT_TYPE");
AccessTokenByCodeRequest accessTokenByCodeRequest = new AccessTokenByCodeRequest();
accessTokenByCodeRequest.setCode(code);
accessTokenByCodeRequest.setAppid(appId);
accessTokenByCodeRequest.setSecret(secret);
accessTokenByCodeRequest.setGrant_type(grantType);
accessTokenByCodeResponse = wechatInterfService.getAccessTokenByCode(accessTokenByCodeRequest);
}
return accessTokenByCodeResponse;
}
} }
package com.yd.rmi.tencent.wechat.service; package com.yd.rmi.tencent.wechat.service;
import com.yd.rmi.tencent.wechat.vo.WeChatInfoByENV;
import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryReqVO; import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryReqVO;
import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryRespVO; import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryRespVO;
import com.yd.rmi.tencent.wechat.vo.WxUserInfo; import com.yd.rmi.tencent.wechat.vo.WxUserInfo;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse; import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest; import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.token.TokenRequest; import com.yd.rmi.tencent.wechatinterf.pojo.token.TokenRequest;
...@@ -11,6 +13,15 @@ import com.yd.rmi.tencent.wechatinterf.pojo.unifiedorder.UnifiedorderResponse; ...@@ -11,6 +13,15 @@ import com.yd.rmi.tencent.wechatinterf.pojo.unifiedorder.UnifiedorderResponse;
import java.util.Map; import java.util.Map;
public interface WechatService { public interface WechatService {
/**
* 微信接口交互 -- access_token
* access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token。
* 注意这和网页授权部分的access_token不是一回事!该接口有调用次数限制,且独立(不依赖于authorize接口)
* @param accessTokenRequest
* @return
*/
String getAccessToken(AccessTokenRequest accessTokenRequest);
public String obtainToken(TokenRequest tokenRequest); public String obtainToken(TokenRequest tokenRequest);
public String obtainTicket(TicketRequest ticketRequest); public String obtainTicket(TicketRequest ticketRequest);
public UnifiedorderResponse unifiedorder(String appId, String openId, String wCpayMethod, String timeExpire, String mchId, Double orderPrice, String planName, String orderNo, String notifyUrl); public UnifiedorderResponse unifiedorder(String appId, String openId, String wCpayMethod, String timeExpire, String mchId, Double orderPrice, String planName, String orderNo, String notifyUrl);
...@@ -68,5 +79,14 @@ public interface WechatService { ...@@ -68,5 +79,14 @@ public interface WechatService {
* @return WxUserInfo * @return WxUserInfo
*/ */
public WxUserInfo getWxUserInfo(String openId, String accessToken); public WxUserInfo getWxUserInfo(String openId, String accessToken);
/**
* 通过环境来获取公众号的access_token
* 在正式环境有两个公众号,银盾保险在线--YDZX 银盾保险经纪--YDBJ
* 测试环境只有一个公众号
* @param gzhName 在正式环境有两个公众号,银盾保险在线--YDZX 银盾保险经纪--YDBJ
* @return
*/
WeChatInfoByENV getWeChatInfoByENV(String gzhName, boolean getAccessToken);
} }
package com.yd.rmi.tencent.wechat.service.impl; package com.yd.rmi.tencent.wechat.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.yd.api.result.CommonResult; import com.yd.api.result.CommonResult;
import com.yd.rmi.cache.SystemConfigService; import com.yd.rmi.cache.SystemConfigService;
import com.yd.dal.entity.tencent.TenInterfRecord; import com.yd.dal.entity.tencent.TenInterfRecord;
...@@ -7,9 +10,11 @@ import com.yd.dal.entity.transaction.TranLog; ...@@ -7,9 +10,11 @@ import com.yd.dal.entity.transaction.TranLog;
import com.yd.dal.service.tencent.TenInterfRecordDALService; import com.yd.dal.service.tencent.TenInterfRecordDALService;
import com.yd.dal.service.transaction.TranLogDALService; import com.yd.dal.service.transaction.TranLogDALService;
import com.yd.rmi.tencent.wechat.service.WechatService; import com.yd.rmi.tencent.wechat.service.WechatService;
import com.yd.rmi.tencent.wechat.vo.WeChatInfoByENV;
import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryReqVO; import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryReqVO;
import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryRespVO; import com.yd.rmi.tencent.wechat.vo.WxNATIVEPayQueryRespVO;
import com.yd.rmi.tencent.wechat.vo.WxUserInfo; import com.yd.rmi.tencent.wechat.vo.WxUserInfo;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse; import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest; import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketResponse; import com.yd.rmi.tencent.wechatinterf.pojo.ticket.TicketResponse;
...@@ -571,6 +576,142 @@ public class WechatServiceImpl implements WechatService { ...@@ -571,6 +576,142 @@ public class WechatServiceImpl implements WechatService {
} }
@Override @Override
public WeChatInfoByENV getWeChatInfoByENV(String gzhName, boolean getAccessToken) {
WeChatInfoByENV weChatInfoByENV = new WeChatInfoByENV();
boolean isProd = SpringContextUtil.isProd();
boolean isLocal = SpringContextUtil.isLocal();
String appId,secret,accessToken;
String grantType = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_TOKEN_GRANT_TYPE");
//根据不同环境和不同公众号获取公众号的appId和secret
if("YDBJ".equals(gzhName)){
appId = systemConfigService.getSingleConfigValue("YD-TENCENT_WECHAT_APPID");
secret = systemConfigService.getSingleConfigValue("YD-TENCENT_WECHAT_APP_SECRET");
}else{
if(isProd){
appId = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APPID");
secret = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APP_SECRET");
}else{
appId = systemConfigService.getSingleConfigValue("AJB-TENCENT_WECHAT_APPID");
secret = systemConfigService.getSingleConfigValue("AJB-TENCENT_WECHAT_APP_SECRET");
}
}
// if(isProd){
// if("YDBJ".equals(gzhName)){
// appId = systemConfigService.getSingleConfigValue("YD-TENCENT_WECHAT_APPID");
// secret = systemConfigService.getSingleConfigValue("YD-TENCENT_WECHAT_APP_SECRET");
// }else{
// appId = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APPID");
// secret = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APP_SECRET");
// }
// }else{
// appId = systemConfigService.getSingleConfigValue("AJB-TENCENT_WECHAT_APPID");
// secret = systemConfigService.getSingleConfigValue("AJB-TENCENT_WECHAT_APP_SECRET");
// }
if(getAccessToken){
AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
accessTokenRequest.setAppid(appId);
accessTokenRequest.setSecret(secret);
accessTokenRequest.setGrant_type(grantType);
//本地环境需要通过dev环境去获取
accessToken = isLocal ? getAccessTokenByDEV(accessTokenRequest) : getAccessToken(accessTokenRequest);
weChatInfoByENV.setAccessToken(accessToken);
}
weChatInfoByENV.setAppId(appId);
weChatInfoByENV.setSecret(secret);
return weChatInfoByENV;
}
/**
* 在本地开发时,通过dev去获取access_token
* @param accessTokenRequest
* @return
*/
private String getAccessTokenByDEV(AccessTokenRequest accessTokenRequest) {
String requestJson = JsonUtil.objToJson(accessTokenRequest);
String responseJson = HttpUtil.postForJson("https://mdev.zuihuibi.cn/api/getAccessToken",requestJson);
JSONObject result = JSON.parseObject(responseJson);
return result.getString("data");
}
@Override
public String getAccessToken(AccessTokenRequest accessTokenRequest) {
refactorRequest(accessTokenRequest);
String grantType = accessTokenRequest.getGrant_type();
String appId = accessTokenRequest.getAppid();
String secret = accessTokenRequest.getSecret();
//1、查询数据库是否存在
String accessToken = getAccessTokenOrTicketByDB(grantType,appId,secret,null,null,"TOKEN");
//2、如果不存在则重新生成
if(Strings.isNullOrEmpty(accessToken)){
AccessTokenResponse accessTokenResponse = wechatInterfService.getAccessToken(accessTokenRequest);
accessToken = accessTokenResponse.getAccess_token();
//保存数据进数据库
String expiresInStr = accessTokenResponse.getExpires_in();
Long expiresIn = Strings.isNullOrEmpty(expiresInStr) ? null : Long.parseLong(expiresInStr);
TenInterfRecord tenCentRecord = new TenInterfRecord();
tenCentRecord.setInterfType("TOKEN");
tenCentRecord.setGrantType(grantType);
tenCentRecord.setAppid(appId);
tenCentRecord.setSecret(secret);
tenCentRecord.setAccessToken(accessToken);
tenCentRecord.setExpiresIn(expiresIn);
tenCentRecord.setErrcode(accessTokenResponse.getErrcode());
tenCentRecord.setErrmsg(accessTokenResponse.getErrmsg());
tenCentRecord.setCreatedAt(new Date());
tenInterfRecordDALService.saveTenInterfRecord(tenCentRecord);
}
return accessToken;
}
private void refactorRequest(AccessTokenRequest accessTokenRequest) {
String appId = accessTokenRequest.getAppid();
String secret = accessTokenRequest.getSecret();
if (Strings.isNullOrEmpty(appId) || Strings.isNullOrEmpty(secret)) {
appId = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APPID");
secret = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_APP_SECRET");
String grantType = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_TOKEN_GRANT_TYPE");
accessTokenRequest.setAppid(appId);
accessTokenRequest.setGrant_type(grantType);
accessTokenRequest.setSecret(secret);
}
}
/**
* 获取获取access_token或者ticket时 查询数据库是否存在相关记录
* @param grantType
* @param appId
* @param secret
* @param pType
* @param accessToken
* @param type "TOKEN":获取access_token TICKET:获取ticket
* @return
*/
private String getAccessTokenOrTicketByDB(String grantType, String appId, String secret, String pType, String accessToken, String type) {
String result = null;
TenInterfRecord tenCentRecord = new TenInterfRecord();
tenCentRecord.setInterfType(type);
List<TenInterfRecord> tenCentInterfaceRecordList = null;
/** 查询最近一天(24H)内 有效期(expires_in)不为空的数据(倒序) **/
if("TOKEN".equals(type)){
tenCentInterfaceRecordList = tenInterfRecordDALService.findByAppIdAndGrantType(appId,grantType);
}else if("TICKET".equals(type)){
tenCentInterfaceRecordList = tenInterfRecordDALService.findByAccessTokenAndIType(accessToken,pType);
}
if(tenCentInterfaceRecordList != null && tenCentInterfaceRecordList.size() >0){
tenCentRecord = tenCentInterfaceRecordList.get(0);
Long expiresIn = tenCentRecord.getExpiresIn();
Date createAt = tenCentRecord.getCreatedAt();
if(expiresIn != null){
Date overdueDate = CommonUtil.dateOperation(createAt, "ADD", "S", expiresIn.intValue());
if(new Date().compareTo(overdueDate) < 0){
result = ("TOKEN".equals(type)) ? tenCentRecord.getAccessToken() : ("TICKET".equals(type)) ? tenCentRecord.getTicket() : null;
}
}
}
return result;
}
@Override
public Map<String, String> jsapiTicketSign(String jsapiTicket, String url) { public Map<String, String> jsapiTicketSign(String jsapiTicket, String url) {
Map<String, String> ret = new HashMap<String, String>(); Map<String, String> ret = new HashMap<String, String>();
String nonceStr = createNonceStr(); String nonceStr = createNonceStr();
...@@ -613,6 +754,11 @@ public class WechatServiceImpl implements WechatService { ...@@ -613,6 +754,11 @@ public class WechatServiceImpl implements WechatService {
return Long.toString(System.currentTimeMillis() / 1000); return Long.toString(System.currentTimeMillis() / 1000);
} }
// private String transaction(String httpURL,String requestXML,String requestMethod){ // private String transaction(String httpURL,String requestXML,String requestMethod){
// HttpsURLConnection conn = null; // HttpsURLConnection conn = null;
// OutputStream out = null; // OutputStream out = null;
......
package com.yd.rmi.tencent.wechat.vo;
public class WeChatInfoByENV {
private String appId;
private String secret;
private String accessToken;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
}
package com.yd.rmi.tencent.wechat.vo.accesstoken;
/**
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318590&token=&lang=zh_CN
* 代公众号发起网页授权
简介
在公众号授权托管给第三方平台后,第三方平台可以根据本文档相关说明,代替授权公众号发起网页授权。关于OAuth2.0的详细介绍,可以参考OAuth2.0协议标准
作为第三方平台开发商,需要拥有自己的appid以及secret(在创建第三方平台并获得审核成功后可以获取),以及确保授权的公众号具备授权作用域的权限,以及用于回调的域名。
授权流程
微信目前支持Authorization code授权模式,主要流程分为两步:
1. 获取code
2. 通过code换取accesstoken
*
*/
public class AccessTokenByCodeRequest {
/*
!!! 开放平台的文档中对于这个接口的描述和公众平台有差异!下面是开放平台中截取的(在公众平台中入参没有component_appid和component_access_token,有secret)
第二步:通过code换取access_token
请求方法
获取第一步的code后,请求以下链接获取access_token:
https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=APPID&code=CODE&grant_type=authorization_code&component_appid=COMPONENT_APPID&component_access_token=COMPONENT_ACCESS_TOKEN
需要注意的是,由于安全方面的考虑,对访问该链接的客户端有IP白名单的要求。
参数说明
参数 是否必须 说明
appid 是 公众号的appid
code 是 填写第一步获取的code参数
grant_type 是 填authorization_code
component_appid 是 服务开发方的appid
component_access_token 是 服务开发方的access_token
返回说明
正确的返回:
{
"access_token":"ACCESS_TOKEN",
"expires_in":7200,
"refresh_token":"REFRESH_TOKEN",
"openid":"OPENID",
"scope":"SCOPE"
}
参数 说明
access_token 接口调用凭证
expires_in access_token接口调用凭证超时时间,单位(秒)
refresh_token 用户刷新access_token
openid 授权用户唯一标识
scope 用户授权的作用域,使用逗号(,)分隔
错误返回样例:
{"errcode":40029,"errmsg":"invalid code"}
*/
private String appid;
private String secret;
private String code;
private String grant_type;
private String component_appid;
private String component_access_token;
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getGrant_type() {
return grant_type;
}
public void setGrant_type(String grant_type) {
this.grant_type = grant_type;
}
public String getComponent_appid() {
return component_appid;
}
public void setComponent_appid(String component_appid) {
this.component_appid = component_appid;
}
public String getComponent_access_token() {
return component_access_token;
}
public void setComponent_access_token(String component_access_token) {
this.component_access_token = component_access_token;
}
}
\ No newline at end of file
package com.yd.rmi.tencent.wechat.vo.accesstoken;
public class AccessTokenByCodeResponse {
// {
// "access_token":"ACCESS_TOKEN",
// "expires_in":7200,
// "refresh_token":"REFRESH_TOKEN",
// "openid":"OPENID",
// "scope":"SCOPE",
// "unionid":"o6_bmasdasdsad6_2sgVt7hMZOPfL"
// }
private String access_token;
private String expires_in;
private String refresh_token;
private String openid;
private String scope;
private String unionid;
private String errcode;
private String errmsg;
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getExpires_in() {
return expires_in;
}
public void setExpires_in(String expires_in) {
this.expires_in = expires_in;
}
public String getRefresh_token() {
return refresh_token;
}
public void setRefresh_token(String refresh_token) {
this.refresh_token = refresh_token;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
public String getErrcode() {
return errcode;
}
public void setErrcode(String errcode) {
this.errcode = errcode;
}
public String getErrmsg() {
return errmsg;
}
public void setErrmsg(String errmsg) {
this.errmsg = errmsg;
}
}
package com.yd.rmi.tencent.wechatinterf.service; package com.yd.rmi.tencent.wechatinterf.service;
import com.yd.rmi.tencent.wechat.vo.accesstoken.AccessTokenByCodeRequest;
import com.yd.rmi.tencent.wechat.vo.accesstoken.AccessTokenByCodeResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenRequest; import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse; import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.authorize.AuthorizeRequest; import com.yd.rmi.tencent.wechatinterf.pojo.authorize.AuthorizeRequest;
...@@ -62,5 +64,30 @@ public interface WechatInterfService { ...@@ -62,5 +64,30 @@ public interface WechatInterfService {
public boolean signValite(UnifiedorderResponse unifiedorderResponse); public boolean signValite(UnifiedorderResponse unifiedorderResponse);
public String transaction(String url, String object, String object2); public String transaction(String url, String object, String object2);
/**
* 微信接口交互 -- 获取access_token
* 获取公众号的access_token
* 注意这和网页授权部分的access_token不是一回事!该接口有调用次数限制,且独立(不依赖于authorize接口)
* @param accessTokenRequest
* @return
*/
AccessTokenResponse getAccessToken(AccessTokenRequest accessTokenRequest);
/**
* 微信交互接口
* @param url 交互地址
* @param requestInfo 请求报文
* @return
*/
String weChatTransaction(String url, String requestInfo);
/**
* 公众号支付时网页授权 -- 通过code获取accessToken
* 这里返回值包含openid
* @param accessTokenByCodeRequest
* @return
*/
AccessTokenByCodeResponse getAccessTokenByCode(AccessTokenByCodeRequest accessTokenByCodeRequest);
} }
...@@ -2,6 +2,8 @@ package com.yd.rmi.tencent.wechatinterf.service.impl; ...@@ -2,6 +2,8 @@ package com.yd.rmi.tencent.wechatinterf.service.impl;
import com.yd.rmi.cache.SystemConfigService; import com.yd.rmi.cache.SystemConfigService;
import com.yd.dal.service.transaction.TranLogDALService; import com.yd.dal.service.transaction.TranLogDALService;
import com.yd.rmi.tencent.wechat.vo.accesstoken.AccessTokenByCodeRequest;
import com.yd.rmi.tencent.wechat.vo.accesstoken.AccessTokenByCodeResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenRequest; import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenRequest;
import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse; import com.yd.rmi.tencent.wechatinterf.pojo.accesstoken.AccessTokenResponse;
import com.yd.rmi.tencent.wechatinterf.pojo.authorize.AuthorizeRequest; import com.yd.rmi.tencent.wechatinterf.pojo.authorize.AuthorizeRequest;
...@@ -26,6 +28,7 @@ import javax.net.ssl.SSLSession; ...@@ -26,6 +28,7 @@ import javax.net.ssl.SSLSession;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -325,4 +328,142 @@ public class WechatInterfServiceImpl implements WechatInterfService { ...@@ -325,4 +328,142 @@ public class WechatInterfServiceImpl implements WechatInterfService {
} }
return sbf.toString(); return sbf.toString();
} }
/**
* 获取access_token:access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token
*/
@Override
public AccessTokenResponse getAccessToken(AccessTokenRequest accessTokenRequest) {
String appId = accessTokenRequest.getAppid();
String grantType = accessTokenRequest.getGrant_type();
String secret = accessTokenRequest.getSecret();
String url = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_TOKEN_URL")+"?"
+"grant_type="+ grantType
+"&appid="+appId
+"&secret="+ secret;
System.out.println("【》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》【微信分享 --4--token-url】"+url+"】");
tranLogDALService.logDB("wechat", "accessToken", "in", accessTokenRequest.getAppid(), url, null, null);
String responseStr = weChatTransaction(url,null);
tranLogDALService.logDB("wechat", "accessToken", "out", accessTokenRequest.getAppid(), responseStr, null, null);
return (AccessTokenResponse)JsonUtil.jsonToObj(responseStr, AccessTokenResponse.class);
}
/**
* 通过code换取accessToken,公众号支付时网页授权,这里返回值有openid
*/
@Override
public AccessTokenByCodeResponse getAccessTokenByCode(AccessTokenByCodeRequest accessTokenByCodeRequest) {
String appId = accessTokenByCodeRequest.getAppid();
String secret = accessTokenByCodeRequest.getSecret();
String grantType = accessTokenByCodeRequest.getGrant_type();
String url = systemConfigService.getSingleConfigValue("TENCENT_WECHAT_ACCESS_TOKEN_URL")+"?"
+"appid="+ appId
+"&secret="+ secret
+"&code="+ accessTokenByCodeRequest.getCode()
+"&grant_type="+ grantType;
tranLogDALService.logDB("wechat", "accessTokenByCode", "in", accessTokenByCodeRequest.getCode(), url, null, null);
String responseStr = weChatTransaction(url,null);
tranLogDALService.logDB("wechat", "accessTokenByCode", "out", accessTokenByCodeRequest.getCode(), responseStr, null, null);
return (AccessTokenByCodeResponse)JsonUtil.jsonToObj(responseStr, AccessTokenByCodeResponse.class);
}
/**
* 微信接口交互
*/
@Override
public String weChatTransaction(String httpURL, String requestXML){
String responseXML;
OutputStream output = null;
InputStream input = null;
try {
URL url = new URL(httpURL);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setReadTimeout(30000);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setAllowUserInteraction(true);
connection.setRequestProperty("Accept-Charset", "utf-8");
connection.setRequestProperty("contentType", "utf-8");
connection.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
connection.connect();
if (requestXML != null && !"".equals(requestXML)) {
output = connection.getOutputStream();
output.write(requestXML.getBytes(StandardCharsets.UTF_8));
}
input = connection.getInputStream();
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if (output != null) {
output.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
StringBuilder stringBuffer = new StringBuilder();
if (input != null) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String string ;
while ((string = reader.readLine()) != null) {
stringBuffer.append(string);
}
} catch (Exception e) {
e.printStackTrace();
}
}
responseXML = stringBuffer.toString();
return responseXML;
/*
InputStream in = null;
String responseXML = null;
try {
URL url = new URL(httpURL);
StringBuilder sbf = new StringBuilder();
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setReadTimeout(30000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setAllowUserInteraction(true);
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setHostnameVerifier((arg0, arg1) -> true);
conn.connect();
in = conn.getInputStream();
if(in != null){
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
String str;
while((str = reader.readLine()) != null){
sbf.append(str);
}
responseXML = sbf.toString();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if(in != null){in.close();}
} catch (Exception e3) {
e3.printStackTrace();
}
}
return responseXML;
*/
}
} }
\ No newline at end of file
package com.yd.util; package com.yd.util;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
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.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
...@@ -8,6 +16,8 @@ import java.util.HashMap; ...@@ -8,6 +16,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class HttpUtil { public class HttpUtil {
public static String defaultEncoding= "utf-8";
/** /**
* 通过url取得文件返回InputStream类型数据 * 通过url取得文件返回InputStream类型数据
* *
...@@ -35,4 +45,30 @@ public class HttpUtil { ...@@ -35,4 +45,30 @@ public class HttpUtil {
return resp; return resp;
} }
} }
/**
* http交互方法---post请求 json类型
* @param url 地址
* @param json json字符串
* @return
*/
public static String postForJson(String url, String json) {
String responseJson = null;
HttpPost httpPost = new HttpPost(url);
CloseableHttpClient client = HttpClients.createDefault();
StringEntity entity = new StringEntity(json,defaultEncoding);
entity.setContentEncoding(defaultEncoding);
entity.setContentType("application/json");
httpPost.setEntity(entity);
try {
HttpResponse response = client.execute(httpPost);
if(response.getStatusLine().getStatusCode() == 200){
HttpEntity httpEntity = response.getEntity();
responseJson = EntityUtils.toString(httpEntity,defaultEncoding);
}
} catch (Exception e) {
e.printStackTrace();
}
return responseJson;
}
} }
...@@ -96,7 +96,27 @@ ...@@ -96,7 +96,27 @@
order by ${orderBy} order by ${orderBy}
</if> </if>
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <select id="findByAppIdAndGrantType" resultType="com.yd.dal.entity.tencent.TenInterfRecord">
select
<include refid="Base_Column_List"></include>
from ag_ten_interf_record t
where t.interf_type = #{type}
and t.appid = #{appId}
and t.grant_type = #{grantType}
and t.expires_in is not null
and t.created_at >(NOW() - INTERVAL 1 DAY) order by created_at desc
</select>
<select id="findByAccessTokenAndIType" resultType="com.yd.dal.entity.tencent.TenInterfRecord">
select
<include refid="Base_Column_List"></include>
from ag_ten_interf_record t
where t.interf_type = #{type}
and t.access_token = #{accessToken}
and t.i_type = #{pType}
and t.expires_in is not null
and t.created_at >(NOW() - INTERVAL 1 DAY) order by created_at desc
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from ag_ten_interf_record delete from ag_ten_interf_record
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</delete> </delete>
......
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