diff --git a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java index 93c2cfe..3b6c80d 100644 --- a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java +++ b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java @@ -1,6 +1,8 @@ package cn.chjyj.szwh.utils; +import cn.chjyj.szwh.utils.pay.StringUtil; import com.alibaba.fastjson2.JSONObject; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.client.utils.URIBuilder; @@ -197,17 +199,17 @@ public class SzwhApiUtils { } /** - * 下载订单资源 + * 下载订单资源 GET 方式 * @param resurl * @param islicode * @param contractIslicode * @return */ public static JSONObject getDownOrdRes(String resurl,String islicode,String contractIslicode){ - String entHost= ProperUtils.getSzwhProp("REAL_URL");//委托系统主机 - //String url=entHost+"/dist/api/v1/synchInfo"; - String url = entHost+ resurl; -// // 使用的token + //String entHost= ProperUtils.getSzwhProp("REAL_URL");//委托系统主机 + String url =resurl+"/"+islicode+"/"+contractIslicode; + log.info("resource_url:"+url); + // 使用的token String sign=SignUtils.createSign("distribute"); Map hmap = new HashMap(); hmap.put("dist_token",sign); @@ -216,4 +218,57 @@ public class SzwhApiUtils { JSONObject json = RequestUtils.GetData(url,hmap,false); return json; } + + /** + * 发票信息请求 + * @param postStr + * @return + */ + public static JSONObject taxRequest(String postStr){ + String turl="https://demo.szhtxx.cn:18182/apiv2/api/invoice/invoiceinfo/billing"; + // 使用的token + String sign=SignUtils.createSign("distribute"); + Map hmap = new HashMap(); + hmap.put("Content-Type","application/json;charset=utf8"); + hmap.put("Accept","application/json;charset=UTF-8"); + // + String reqtoken = "bearer "+taxReqToken(); + hmap.put("Authorization",reqtoken); + hmap.put("taxNo","440301999999980"); + hmap.put("machineNo","2"); + JSONObject json = RequestUtils.postData(turl,postStr,hmap); + log.info("发票信息结果::"+postStr+",ret:"+json); + return json; + } + + /** + * 发票请求token + * @return + */ + public static String taxReqToken(){ + String turl="https://demo.szhtxx.cn:18182/apiv2/oauth/token"; + //检查缓存中是否有该记录 + String key ="IRToken"; + String token = (String)RedisUtil.get(key); + if(StringUtils.isNotBlank(token)){ + return token; + } + //请求的内容 + JSONObject reqmap = new JSONObject(); + reqmap.put("client_id","apiuser"); + reqmap.put("client_secret","secret"); + reqmap.put("grant_type","password"); + reqmap.put("username","440301999999980"); + reqmap.put("password","123456"); + // + Map hmap = new HashMap(); + hmap.put("Content-Type","application/json;charset=utf8"); + // + JSONObject json = RequestUtils.postData(turl,reqmap.toJSONString(),hmap); + log.info("发票信息结果::"+reqmap.toJSONString()+",ret:"+json); + String tokenStr =json.getString("access_token"); + //做缓存 + RedisUtil.set(key,token,3600); + return tokenStr; + } }