|
|
@@ -16,12 +16,16 @@
|
|
|
*/
|
|
|
package org.springblade.deliver.goods.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.springblade.client.entity.BasicCorpsProfitChange;
|
|
|
import org.springblade.client.entity.CorpsDesc;
|
|
|
import org.springblade.client.entity.StorageDesc;
|
|
|
@@ -31,18 +35,20 @@ import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
-import org.springblade.deliver.goods.entity.Delivery;
|
|
|
-import org.springblade.deliver.goods.entity.DeliveryFees;
|
|
|
-import org.springblade.deliver.goods.entity.DeliveryFiles;
|
|
|
-import org.springblade.deliver.goods.entity.DeliveryItems;
|
|
|
+import org.springblade.deliver.goods.entity.*;
|
|
|
import org.springblade.deliver.goods.enums.DeliveryEnum;
|
|
|
import org.springblade.deliver.goods.enums.DeliveryStatusEnum;
|
|
|
-import org.springblade.deliver.goods.mapper.DeliveryItemsMapper;
|
|
|
+import org.springblade.deliver.goods.mapper.*;
|
|
|
import org.springblade.deliver.goods.service.IDeliveryItemsService;
|
|
|
+import org.springblade.deliver.goods.tool.JdyTool;
|
|
|
import org.springblade.deliver.goods.vo.DeliveryVO;
|
|
|
-import org.springblade.deliver.goods.mapper.DeliveryMapper;
|
|
|
import org.springblade.deliver.goods.service.IDeliveryService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.deliver.goods.vojo.JDYassist;
|
|
|
+import org.springblade.deliver.goods.vojo.JDYentries;
|
|
|
+import org.springblade.deliver.goods.vojo.JDYitems;
|
|
|
+
|
|
|
+
|
|
|
import org.springblade.mocha.entity.BusinessOverpaymentItem;
|
|
|
import org.springblade.mocha.entity.Overpayment;
|
|
|
import org.springblade.mocha.feign.IBusinessOverpaymentClient;
|
|
|
@@ -58,8 +64,17 @@ import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.net.ssl.*;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.security.SecureRandom;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 发货通知单 服务实现类
|
|
|
@@ -82,6 +97,19 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
|
|
|
private ICorpsProfitChangeClient corpsProfitChangeClient;
|
|
|
private IOrderDescClient orderDescClient;
|
|
|
private IBusinessOverpaymentClient iBusinessOverpaymentClient;
|
|
|
+ private static final String DEFAULT_CHARSET = "UTF-8";
|
|
|
+
|
|
|
+ private static final String METHOD_POST = "POST";
|
|
|
+
|
|
|
+ private JdTenantMapper jdTenantMapper;
|
|
|
+
|
|
|
+ private JdModuleMapper moduleMapper;
|
|
|
+
|
|
|
+ private JdCorpsMapper corpsMapper;
|
|
|
+
|
|
|
+ private DeliveryItemsMapper deliveryItemsMapper;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private final DeliveryItemsServiceImpl iDeliveryItemsService;
|
|
|
|
|
|
@@ -340,13 +368,57 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
|
|
|
{
|
|
|
throw new SecurityException("未查到相关数据,操作失败");
|
|
|
}
|
|
|
+
|
|
|
+ Long corpId = select.getCorpId();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeliveryItems> deliveryItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ deliveryItemsLambdaQueryWrapper
|
|
|
+ .eq(DeliveryItems::getPid,deliveryId)
|
|
|
+ .eq(DeliveryItems::getIsDeleted,0);
|
|
|
+ List<DeliveryItems> deliveryItems = deliveryItemsMapper.selectList(deliveryItemsLambdaQueryWrapper);
|
|
|
+ BigDecimal pricetotal = deliveryItems.stream().filter(e -> e.getPrice() != null).map(DeliveryItems::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ String acoount=CollectionUtils.isEmpty(deliveryItems)?"0":pricetotal.toString();
|
|
|
+ String corpName=null;
|
|
|
+ String orderNo=select.getOrderNo();
|
|
|
+ String wareHouse=null;
|
|
|
+ R<CorpsDesc> corpMessage = corpsDescClient.getCorpMessage(corpId);
|
|
|
+ if(corpMessage.isSuccess()&&corpMessage.getData()!=null)
|
|
|
+ {
|
|
|
+ corpName=corpMessage.getData().getCname();
|
|
|
+ }
|
|
|
+ //仓库信息
|
|
|
+ StorageDesc storageDesc = iStorageClient.findById(select.getStorageId());
|
|
|
+ if(storageDesc!=null)
|
|
|
+ {
|
|
|
+ wareHouse=storageDesc.getCname();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Long storageId = select.getStorageId();
|
|
|
+ //收货凭证
|
|
|
+ if (select.getTenantId().equals("681169"))
|
|
|
+ {
|
|
|
+ //todo
|
|
|
+ try
|
|
|
+ {
|
|
|
+ String accountName="金蝶开发者测试账套";
|
|
|
+ //测试账套-收货生成凭证
|
|
|
+ this.testTakeGoodsSaveVoucher(accountName,corpName,wareHouse,acoount,orderNo);
|
|
|
+ }
|
|
|
+ catch (Exception exception)
|
|
|
+ {
|
|
|
+ throw new SecurityException(exception.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if(select.getDeliveryStatus()==null||select.getDeliveryStatus().equals("已收货"))
|
|
|
{
|
|
|
throw new SecurityException("此单据已收货或者不存在,禁止重复操作");
|
|
|
}
|
|
|
|
|
|
|
|
|
- Long corpId = select.getCorpId();
|
|
|
+
|
|
|
|
|
|
//保存收货单主表 和 收货单明细
|
|
|
this.submitDelivery(delivery);
|
|
|
@@ -657,4 +729,397 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //收货生成凭证
|
|
|
+ public void testTakeGoodsSaveVoucher(String accountName,String copsName,String warehouse ,String acoount,String orderNo) throws Exception
|
|
|
+ {
|
|
|
+
|
|
|
+ //非达沃特用户直接返回
|
|
|
+ if(!AuthUtil.getTenantId().equals("681169"))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取token
|
|
|
+ String token = this.getAccountGroupRequest();
|
|
|
+ //获取套账url
|
|
|
+ String getAccountUrl="https://api.kingdee.com/jdy/sys/accountGroup?access_token="+token;
|
|
|
+ Map<String, String> urlParams=new HashMap<>();
|
|
|
+ String result = this.doPost(getAccountUrl, urlParams);
|
|
|
+ JdyTool.getAccountGroup getAccountGroup = JSONObject.parseObject(result, JdyTool.getAccountGroup.class);
|
|
|
+
|
|
|
+ List<JdyTool.AccountGroup> list=new ArrayList<>();
|
|
|
+ if(!CollectionUtils.isNotEmpty(getAccountGroup.getData()))
|
|
|
+ {
|
|
|
+ throw new SecurityException("操作失败,暂无账套信息");
|
|
|
+ }
|
|
|
+ //获取此账号下,全部账套
|
|
|
+ getAccountGroup.getData().forEach(e->{
|
|
|
+ list.addAll(e.getAccountGroups());
|
|
|
+ });
|
|
|
+ //匹配账套
|
|
|
+ List<JdyTool.AccountGroup> groupList = list.stream().filter(e -> e.getAccountName().equals(accountName)).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isNotEmpty(groupList))
|
|
|
+ {
|
|
|
+ throw new SecurityException("未找到: "+accountName+" 的套账信息");
|
|
|
+ }
|
|
|
+ JdyTool.AccountGroup group = groupList.get(0);
|
|
|
+
|
|
|
+
|
|
|
+ //1.获取套账信息
|
|
|
+ LambdaQueryWrapper<JdTenant> jdTenantLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ jdTenantLambdaQueryWrapper
|
|
|
+ .eq(JdTenant::getIsEnable,1)
|
|
|
+ .eq(JdTenant::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .eq(JdTenant::getAccountName,accountName);
|
|
|
+ JdTenant jdTenant = jdTenantMapper.selectOne(jdTenantLambdaQueryWrapper);
|
|
|
+ if(jdTenant==null)
|
|
|
+ {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //2.收货,组装model,保存凭证
|
|
|
+ toTakeJinDie(orderNo,acoount,copsName,warehouse,jdTenant.getAccountId(),group.getGroupName(),jdTenant);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //金蝶保存凭证测试-销售生成凭证
|
|
|
+ public void toTakeJinDie(String orderNo,String acoount,String copsName,String warehouse,String accountId,String groupName,JdTenant jdTenant) {
|
|
|
+ //不是某一家 直接返回
|
|
|
+ if (!AuthUtil.getTenantId().equals("681169"))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JDYitems item = new JDYitems();
|
|
|
+ item.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ List<JDYentries> entriesList = new ArrayList<>();
|
|
|
+ List<JDYitems> jdYitems = new ArrayList<>();
|
|
|
+
|
|
|
+ //财务借方
|
|
|
+ JDYentries d = new JDYentries();
|
|
|
+ d.setDc("1");
|
|
|
+
|
|
|
+ LambdaQueryWrapper<JdModule> dLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ dLambdaQueryWrapper
|
|
|
+ .eq(JdModule::getAccountId,accountId)
|
|
|
+ .eq(JdModule::getModule,"收货")
|
|
|
+ .eq(JdModule::getDc,"1")
|
|
|
+ .last("limit 1")
|
|
|
+ .eq(JdModule::getTenantId,AuthUtil.getTenantId());
|
|
|
+ JdModule dModule = moduleMapper.selectOne(dLambdaQueryWrapper);
|
|
|
+ if(dModule==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("获取销售订单科目号失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ d.setExplanation(orderNo + "采购入库");
|
|
|
+ d.setAccount_number(dModule.getProjectCode());
|
|
|
+ d.setDebitamount(acoount);
|
|
|
+
|
|
|
+
|
|
|
+ //===========辅助核算=================
|
|
|
+ List<JDYassist> dList=new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ warehouse="测试仓库";//具体到时候用哪个,需要关联查询传参,今天先用测试的
|
|
|
+ LambdaQueryWrapper<JdCorps> corpsQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ corpsQueryWrapper
|
|
|
+ .eq(JdCorps::getCorpsType,4)
|
|
|
+ .eq(JdCorps::getAccountId,accountId)
|
|
|
+ .eq(JdCorps::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .last("limit 1")
|
|
|
+ .eq(JdCorps::getCorpsName,warehouse);
|
|
|
+ JdCorps jdCorps = corpsMapper.selectOne(corpsQueryWrapper);
|
|
|
+
|
|
|
+ JDYassist jdYassist=new JDYassist();
|
|
|
+ jdYassist.setType("bd_store");
|
|
|
+ if(jdCorps!=null)
|
|
|
+ {
|
|
|
+ jdYassist.setNumber(jdCorps.getCorpsCode());
|
|
|
+ }
|
|
|
+ dList.add(jdYassist);
|
|
|
+ d.setAssist(dList);
|
|
|
+ //===========辅助核算=================
|
|
|
+ entriesList.add(d);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //财务贷方
|
|
|
+ JDYentries c = new JDYentries();
|
|
|
+ c.setDc("-1");
|
|
|
+
|
|
|
+ LambdaQueryWrapper<JdModule> cLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ cLambdaQueryWrapper
|
|
|
+ .eq(JdModule::getAccountId,accountId)
|
|
|
+ .eq(JdModule::getModule,"收货")
|
|
|
+ .eq(JdModule::getDc,"-1")
|
|
|
+ .last("limit 1")
|
|
|
+ .eq(JdModule::getTenantId,AuthUtil.getTenantId());
|
|
|
+ JdModule cModule = moduleMapper.selectOne(cLambdaQueryWrapper);
|
|
|
+ if(cModule==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("获取销售订单科目号失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ c.setExplanation(orderNo +"采购入库");
|
|
|
+ c.setAccount_number(cModule.getProjectCode());
|
|
|
+ c.setCreditamount(acoount);
|
|
|
+
|
|
|
+
|
|
|
+ //===========辅助核算=================
|
|
|
+ List<JDYassist> cList=new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ copsName="测试供应商";//具体到时候用哪个,需要关联查询传参,今天先用测试的
|
|
|
+ LambdaQueryWrapper<JdCorps> corpsQueryWrapper2=new LambdaQueryWrapper<>();
|
|
|
+ corpsQueryWrapper2
|
|
|
+ .eq(JdCorps::getCorpsType,2)
|
|
|
+ .eq(JdCorps::getAccountId,accountId)
|
|
|
+ .eq(JdCorps::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .last("limit 1")
|
|
|
+ .eq(JdCorps::getCorpsName,copsName);
|
|
|
+ JdCorps jdCorps2 = corpsMapper.selectOne(corpsQueryWrapper2);
|
|
|
+
|
|
|
+ JDYassist jdYassist2=new JDYassist();
|
|
|
+ jdYassist2.setType("bd_supplier");
|
|
|
+ if(jdCorps!=null)
|
|
|
+ {
|
|
|
+ jdYassist2.setNumber(jdCorps2.getCorpsCode());
|
|
|
+ }
|
|
|
+ cList.add(jdYassist2);
|
|
|
+ c.setAssist(cList);
|
|
|
+ //===========辅助核算=================
|
|
|
+ entriesList.add(c);
|
|
|
+
|
|
|
+
|
|
|
+ //组装数据
|
|
|
+ item.setEntries(entriesList);
|
|
|
+ jdYitems.add(item);
|
|
|
+ try {
|
|
|
+ String token = this.getAccountGroupRequest();
|
|
|
+ String saveUrl="http://api.kingdee.com/jdy/gl/voucher_save?access_token="+token;
|
|
|
+ JdyTool.testSaveVoucher(saveUrl,accountId,groupName,jdYitems);
|
|
|
+ } catch (Exception exception) {
|
|
|
+ throw new SecurityException("操作失败,保存金蝶错误:"+exception.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //测试获取AccountGroupRequest
|
|
|
+ public String getAccountGroupRequest() throws Exception
|
|
|
+ {
|
|
|
+ //校验当前租户配置,如果存在配置,返回token
|
|
|
+ LambdaQueryWrapper<JdTenant> jdTenantLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ jdTenantLambdaQueryWrapper
|
|
|
+ .eq(JdTenant::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .eq(JdTenant::getIsEnable,1);
|
|
|
+ JdTenant jdTenant = jdTenantMapper.selectOne(jdTenantLambdaQueryWrapper);
|
|
|
+ if(jdTenant==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("当前租户未配置凭证信息");
|
|
|
+ }
|
|
|
+ //获取测试账套token的url
|
|
|
+ //String getTokenUrl="https://api.kingdee.com/auth/user/access_token";
|
|
|
+ String getTokenUrl="https://api.kingdee.com/auth/user/access_token?client_id=" +jdTenant.getClientId()+
|
|
|
+ "&client_secret=" +jdTenant.getClientSecret()+
|
|
|
+ "&username=" +jdTenant.getUsername()+
|
|
|
+ "&password="+jdTenant.getPassword();
|
|
|
+ Map<String, String> urlParams=new HashMap<>();
|
|
|
+ /* urlParams.put("clientId",jdTenant.getClientId());
|
|
|
+ urlParams.put("client_secret",jdTenant.getClientSecret());
|
|
|
+ urlParams.put("username",jdTenant.getUsername());
|
|
|
+ urlParams.put("password",jdTenant.getPassword());*/
|
|
|
+
|
|
|
+ String result = this.doGet(getTokenUrl, urlParams);
|
|
|
+ tokenDTO tokenDTO = JSONObject.parseObject(result, tokenDTO.class);
|
|
|
+ if(tokenDTO.errcode==1006)
|
|
|
+ {
|
|
|
+ throw new SecurityException("当前密码错误次数超过限定值");
|
|
|
+ }
|
|
|
+ String accessToken = tokenDTO.getData().getAccess_token();
|
|
|
+ return accessToken;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String doGet(String url, Map<String, String> urlParams)
|
|
|
+ throws IOException {
|
|
|
+ if (isEmpty(url)) {
|
|
|
+ throw new IllegalArgumentException("The parameter 'url' can not be null or blank.");
|
|
|
+ }
|
|
|
+ url += buildQuery(urlParams, "UTF-8");
|
|
|
+ HttpURLConnection conn = getConnection(new URL(url), "GET");
|
|
|
+ String s = getResponseAsString(conn);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String doPost(String url, Map<String, String> urlParams) throws IOException {
|
|
|
+ if (isEmpty(url)) {
|
|
|
+ throw new IllegalArgumentException("The parameter 'url' can not be null or blank.");
|
|
|
+ }
|
|
|
+ url += buildQuery(urlParams, DEFAULT_CHARSET);
|
|
|
+ HttpURLConnection conn = getConnection(new URL(url), METHOD_POST);
|
|
|
+ /* conn.setConnectTimeout(connectTimeOut);
|
|
|
+ conn.setReadTimeout(readTimeOut);
|
|
|
+ conn.getOutputStream().write(requestJson.getBytes(DEFAULT_CHARSET));*/
|
|
|
+
|
|
|
+ String s = getResponseAsString(conn);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private boolean isEmpty(String str) {
|
|
|
+ return str == null || str.trim().length() == 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public String buildQuery(Map<String, String> params, String charset) throws UnsupportedEncodingException {
|
|
|
+ if (params == null || params.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ boolean first = true;
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
+ if (first) {
|
|
|
+ sb.append("?");
|
|
|
+ first = false;
|
|
|
+ } else {
|
|
|
+ sb.append("&");
|
|
|
+ }
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ if (areNotEmpty(key, value)) {
|
|
|
+ sb.append(key).append("=").append(URLEncoder.encode(value, charset));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public boolean areNotEmpty(String... values) {
|
|
|
+ if (values == null || values.length == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String value : values) {
|
|
|
+ if (isEmpty(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HttpURLConnection getConnection(URL url, String method)
|
|
|
+ throws IOException {
|
|
|
+
|
|
|
+ HttpURLConnection conn;
|
|
|
+ if ("https".equals(url.getProtocol())) {
|
|
|
+ SSLContext ctx;
|
|
|
+ try {
|
|
|
+ ctx = SSLContext.getInstance("TLS");
|
|
|
+ ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() },
|
|
|
+ new SecureRandom());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IOException(e);
|
|
|
+ }
|
|
|
+ HttpsURLConnection connHttps = (HttpsURLConnection) url.openConnection();
|
|
|
+ connHttps.setSSLSocketFactory(ctx.getSocketFactory());
|
|
|
+ connHttps.setHostnameVerifier(new HostnameVerifier() {
|
|
|
+
|
|
|
+ public boolean verify(String hostname, SSLSession session) {
|
|
|
+ return true;// 默认都认证通过
|
|
|
+ }
|
|
|
+ });
|
|
|
+ conn = connHttps;
|
|
|
+ } else {
|
|
|
+ conn = (HttpURLConnection) url.openConnection();
|
|
|
+ }
|
|
|
+ conn.setRequestMethod(method);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ conn.setRequestProperty("Connection", "Keep-Alive");
|
|
|
+ return conn;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class DefaultTrustManager implements X509TrustManager {
|
|
|
+
|
|
|
+ public X509Certificate[] getAcceptedIssuers() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkClientTrusted(X509Certificate[] cert, String oauthType)
|
|
|
+ throws java.security.cert.CertificateException {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkServerTrusted(X509Certificate[] cert, String oauthType)
|
|
|
+ throws java.security.cert.CertificateException {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String getResponseAsString(HttpURLConnection conn) throws IOException {
|
|
|
+ InputStream es = conn.getErrorStream();
|
|
|
+ if (es == null) {
|
|
|
+ return getStreamAsString(conn.getInputStream(), "UTF-8");
|
|
|
+ } else {
|
|
|
+ String msg = getStreamAsString(es, "UTF-8");
|
|
|
+ if (isEmpty(msg)) {
|
|
|
+ throw new IOException(conn.getResponseCode() + " : " + conn.getResponseMessage());
|
|
|
+ } else {
|
|
|
+ throw new IOException(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStreamAsString(InputStream input, String charset) throws IOException {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ BufferedReader bf = null;
|
|
|
+ try {
|
|
|
+ bf = new BufferedReader(new InputStreamReader(input, charset));
|
|
|
+ String str;
|
|
|
+ while ((str = bf.readLine()) != null) {
|
|
|
+ sb.append(str);
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ } finally {
|
|
|
+ if (bf != null) {
|
|
|
+ bf.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ @Data
|
|
|
+ public static class tokenDTO
|
|
|
+ {
|
|
|
+ private Long errcode;
|
|
|
+
|
|
|
+ private String description;
|
|
|
+
|
|
|
+ private tokenData data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class tokenData
|
|
|
+ {
|
|
|
+ private String access_token;
|
|
|
+ private String avatar;
|
|
|
+ private String expires;
|
|
|
+ private String expires_in;
|
|
|
+ private String gender;
|
|
|
+ private String nickname;
|
|
|
+ private String uid;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|