|
|
@ -24,8 +24,12 @@ import com.bnyer.img.vo.FhSessionInfoVo; |
|
|
import com.bnyer.img.vo.FhUserInfoVo; |
|
|
import com.bnyer.img.vo.FhUserInfoVo; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.http.HttpEntity; |
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
|
import javax.crypto.Cipher; |
|
|
import javax.crypto.Cipher; |
|
|
@ -101,20 +105,22 @@ public class FhUserServiceImpl implements FhUserService { |
|
|
* @return - |
|
|
* @return - |
|
|
*/ |
|
|
*/ |
|
|
private FhSessionInfoVo getSessionInfo(String code) { |
|
|
private FhSessionInfoVo getSessionInfo(String code) { |
|
|
Map<String,String> map = new HashMap<>(); |
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
map.put("appid",fhConfig.getAppId()); |
|
|
headers.add("Content-Type", "application/x-www-form-urlencoded"); |
|
|
map.put("app_secret", fhConfig.getSecret()); |
|
|
MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); |
|
|
map.put("js_code", code); |
|
|
postParameters.add("app_id", fhConfig.getAppId()); |
|
|
JSONObject sessionInfo = restTemplate.postForObject(fhConfig.getSessionInfoUrl(), map, JSONObject.class); |
|
|
postParameters.add("app_secret", fhConfig.getSecret()); |
|
|
|
|
|
postParameters.add("js_code", code); |
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(postParameters, headers); |
|
|
|
|
|
JSONObject sessionInfo = restTemplate.postForObject(fhConfig.getSessionInfoUrl(), httpEntity, JSONObject.class); |
|
|
if(!sessionInfo.getString("result").equals(TiktokConstant.FH_SUCCESS)){ |
|
|
if(!sessionInfo.getString("result").equals(TiktokConstant.FH_SUCCESS)){ |
|
|
//log.error("快手授权session接口调用失败,错误状态码为:【{}】,错误信息为:【{}】",sessionInfo.getString("result"),sessionInfo.getString("err_tips"));
|
|
|
//log.error("快手授权session接口调用失败,错误状态码为:【{}】,错误信息为:【{}】",sessionInfo.getString("result"),sessionInfo.getString("err_tips"));
|
|
|
throw new ServiceException("快手授权session接口调用失败!",TiktokConstant.FH_AUTH_ERROR); |
|
|
throw new ServiceException("快手授权session接口调用失败!",TiktokConstant.FH_AUTH_ERROR); |
|
|
} |
|
|
} |
|
|
//调用成功,组装返回数据
|
|
|
//调用成功,组装返回数据
|
|
|
JSONObject data = sessionInfo.getJSONObject("data"); |
|
|
|
|
|
FhSessionInfoVo result = new FhSessionInfoVo(); |
|
|
FhSessionInfoVo result = new FhSessionInfoVo(); |
|
|
result.setSessionKey(data.getString("session_key")); |
|
|
result.setSessionKey(sessionInfo.getString("session_key")); |
|
|
result.setOpenId(data.getString("open_id")); |
|
|
result.setOpenId(sessionInfo.getString("open_id")); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -158,6 +164,7 @@ public class FhUserServiceImpl implements FhUserService { |
|
|
fhUser.setFhCode(Sm4Util.sm4Encryption(openId)); |
|
|
fhUser.setFhCode(Sm4Util.sm4Encryption(openId)); |
|
|
fhUser.setCreateTime(new Date()); |
|
|
fhUser.setCreateTime(new Date()); |
|
|
fhUser.setUpdateTime(new Date()); |
|
|
fhUser.setUpdateTime(new Date()); |
|
|
|
|
|
fhUser.setIsShow("1"); |
|
|
fhUserMapper.insert(fhUser); |
|
|
fhUserMapper.insert(fhUser); |
|
|
log.info("快手用户【{}】创建成功!", openId); |
|
|
log.info("快手用户【{}】创建成功!", openId); |
|
|
return fhUser; |
|
|
return fhUser; |
|
|
|