|
@ -6,12 +6,20 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.wlyy.service.third.ylz.model.YLZAccessToken;
|
|
|
import com.yihu.wlyy.service.third.ylz.model.YLZUser;
|
|
|
import com.yihu.wlyy.service.third.ylz.model.YLZUserCard;
|
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
|
import com.ylzinfo.ehc.empi.sdk.EhcEmpiClient;
|
|
|
import com.ylzinfo.ehc.empi.sdk.dto.request.AuthorizationTokenRequest;
|
|
|
import com.ylzinfo.onepay.sdk.OnepayDefaultClient;
|
|
|
import com.ylzinfo.onepay.sdk.domain.RequestParams;
|
|
|
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
|
|
|
import com.ylzinfo.onepay.sdk.exception.PayException;
|
|
|
import com.ylzinfo.onepay.sdk.utils.DateUtil;
|
|
|
import com.ylzinfo.onepay.sdk.utils.SecurityUtil;
|
|
|
import com.ylzinfo.onepay.sdk.utils.Signature;
|
|
|
import com.ylzinfo.onepay.sdk.utils.StringUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -35,8 +43,10 @@ public class YLZUserService {
|
|
|
|
|
|
@Value("${ylz.appId}")
|
|
|
private String appId;
|
|
|
@Value("${ylz.aapSecret}")
|
|
|
private String aapSecret;
|
|
|
@Value("${ylz.termId}")
|
|
|
private String termId;
|
|
|
@Value("${ylz.appSecret}")
|
|
|
private String appSecret;
|
|
|
@Value("${ylz.redirectUrl}")
|
|
|
private String redirectUrl;
|
|
|
|
|
@ -44,48 +54,51 @@ public class YLZUserService {
|
|
|
private String signType = "MD5";
|
|
|
private String encryptType = "AES";
|
|
|
private String responseType = "token";
|
|
|
@Autowired
|
|
|
private HttpClientUtil httpClientUtil;
|
|
|
|
|
|
|
|
|
public String getAccessToken(String openId) {
|
|
|
public String getAccessToken() {
|
|
|
try {
|
|
|
YLZAccessToken ylzAccessToken = null;
|
|
|
String result = null;
|
|
|
OnepayDefaultClient onepayClient = new OnepayDefaultClient(
|
|
|
empiUimcAuthorization,
|
|
|
appId,
|
|
|
aapSecret, signType, encryptType);
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setSignType(signType);
|
|
|
requestParams.setEncryptType(encryptType);
|
|
|
|
|
|
//业务参数
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("response_type", responseType); //接入应用结算业务流水号
|
|
|
params.put("redirect_url", redirectUrl);
|
|
|
params.put("domain_cust_id", openId);
|
|
|
|
|
|
requestParams.setParam(params);
|
|
|
logger.info("requestParams:" + requestParams.toString());
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
|
|
|
if (OnepayDefaultClient.isSuccessful(res)) {
|
|
|
result = JSON.toJSONString(res.getParam());
|
|
|
logger.info("易联众返回结果:" + result);
|
|
|
// 新增保存数据
|
|
|
JSONObject resultJson = JSON.parseObject(result).getJSONObject("biz_content");
|
|
|
|
|
|
ylzAccessToken = new YLZAccessToken();
|
|
|
ylzAccessToken.setAccessToken(resultJson.getString("access_token"));
|
|
|
ylzAccessToken.setExpiresIn(resultJson.getInteger("expires_in"));
|
|
|
ylzAccessToken.setCreateTime(new Date());
|
|
|
EhcEmpiClient empiClient = new EhcEmpiClient(gatewayURL, appId, appSecret, termId, "1.0", signType, encryptType);
|
|
|
try {
|
|
|
AuthorizationTokenRequest params = new AuthorizationTokenRequest();
|
|
|
params.setRedirectUrl(redirectUrl);
|
|
|
params.setUserName("48");
|
|
|
String url = empiClient.createUrl("gatewayPage", empiUimcAuthorization, params);
|
|
|
String responseStr = httpClientUtil.get(url, "UTF-8");
|
|
|
net.sf.json.JSONObject responseJSON = net.sf.json.JSONObject.fromObject(responseStr);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return ylzAccessToken.getAccessToken();
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private String initParams(RequestParams requestParams) throws PayException {
|
|
|
|
|
|
String sign = Signature.createSign(requestParams, this.appSecret);
|
|
|
requestParams.setSign(sign);
|
|
|
|
|
|
String requestMessage;
|
|
|
try {
|
|
|
logger.info("加密前报文:" + JSONObject.toJSONString(requestParams));
|
|
|
requestMessage = SecurityUtil.encrypt(JSONObject.toJSONString(requestParams.getParam()), this.encryptType, this.appSecret, this.appId);
|
|
|
logger.info("加密后报文:" + requestMessage);
|
|
|
requestParams.setEncryptData(requestMessage);
|
|
|
} catch (Exception var11) {
|
|
|
throw new PayException("请求报文加密失败");
|
|
|
}
|
|
|
|
|
|
requestParams.setParam((Object) null);
|
|
|
requestMessage = JSON.toJSONString(requestParams);
|
|
|
System.out.println("请求参数报文:" + requestMessage);
|
|
|
return requestMessage;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -97,7 +110,7 @@ public class YLZUserService {
|
|
|
OnepayDefaultClient onepayClient = new OnepayDefaultClient(
|
|
|
empiUimcQuery,
|
|
|
appId,
|
|
|
aapSecret, signType, encryptType);
|
|
|
appSecret, signType, encryptType);
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|