‘linchangsheng’ vor 6 Monaten
Ursprung
Commit
cd54813dd0

+ 1 - 1
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/policy/WorkerLogic.java

@@ -203,7 +203,7 @@ public class WorkerLogic {
             return new Page<>();
 
         Page<WorkerPolicy> page = workerPolicyService.lambdaQuery()
-                .eq(WorkerPolicy::getWebsitUserId,collect)
+                .in(WorkerPolicy::getWebsitUserId,collect)
                 .eq(WorkerPolicy::getPolicyType,"AC")
                 .eq(WorkerPolicy::getType,"IN")
                 .page(new Page<>(pageNum, pageSize));

+ 20 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/CommonParam.java

@@ -0,0 +1,20 @@
+package com.gree.mall.manager.bean;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@ApiModel
+@Data
+public class CommonParam {
+
+    @ApiModelProperty("appId")
+    private String appId;
+    @ApiModelProperty("appKey")
+    private String appKey;
+    @ApiModelProperty("json字符串")
+    private String json;
+    @ApiModelProperty("appPath")
+    private String appPath;
+
+}

+ 32 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/OutAppDefaultReq.java

@@ -0,0 +1,32 @@
+package com.gree.mall.manager.bean;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@ApiModel
+public class OutAppDefaultReq {
+    @ApiModelProperty("接入ID")
+    private String appid;
+    @ApiModelProperty("时间戳")
+    private String timestamp;
+    @ApiModelProperty("签名类型")
+    private String signType;
+    @ApiModelProperty("签名")
+    private String sign;
+    @ApiModelProperty("版本")
+    private String version;
+    @ApiModelProperty("接口名称")
+    private String apiPath;
+    @ApiModelProperty("业务参数")
+    private String bizContent;
+    @ApiModelProperty("六位随机字符")
+    private String rand;
+}

+ 115 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/common/CryptTool.java

@@ -0,0 +1,115 @@
+package com.gree.mall.manager.controller.common;
+
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+
+import javax.crypto.*;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.security.*;
+
+public class CryptTool {
+    public CryptTool() {
+    }
+
+    public static String byte2hex(byte[] b) {
+        StringBuffer stringBuffer = new StringBuffer();
+        String temp = null;
+
+        for(int i = 0; i < b.length; ++i) {
+            temp = Integer.toHexString(b[i] & 255);
+            if (temp.length() == 1) {
+                stringBuffer.append("0").append(temp);
+            } else {
+                stringBuffer.append(temp);
+            }
+        }
+
+        return stringBuffer.toString();
+    }
+
+    public static byte[] decodeBase64(String key) {
+        return Base64.decodeBase64(key);
+    }
+
+    public static SecretKeySpec initAESSecretKey(String secretKeySource) throws NoSuchAlgorithmException, DecoderException, UnsupportedEncodingException {
+        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
+        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
+        byte[] decodeHex = Hex.decodeHex(sha256(secretKeySource).toCharArray());
+        secureRandom.setSeed(decodeHex);
+        keyGen.init(128, secureRandom);
+        SecretKey secretKey = keyGen.generateKey();
+        byte[] secretKeyEncoded = secretKey.getEncoded();
+        SecretKeySpec key = new SecretKeySpec(secretKeyEncoded, "AES");
+        Security.addProvider(new BouncyCastleProvider());
+        return key;
+    }
+
+    public static String decryptAES(String source, String secretKey) {
+        try {
+            byte[] sourceBytes = decodeBase64(source);
+            SecretKeySpec secretKeySpec = initAESSecretKey(secretKey);
+            byte[] decryptBytes = decrypt(source.getBytes(), secretKeySpec);
+            return new String(decryptBytes, "utf8");
+        } catch (Exception var5) {
+            throw new RuntimeException("AES算法解密失败", var5);
+        }
+    }
+
+    private static byte[] decrypt(byte[] source, SecretKeySpec secretKeySpec) throws NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException {
+        Cipher cipher = Cipher.getInstance(secretKeySpec.getAlgorithm());
+        cipher.init(2, secretKeySpec);
+        return cipher.doFinal(source);
+    }
+
+    public static String digest(byte[] inputBytes, String algorithm) throws NoSuchAlgorithmException {
+        String outputStr = null;
+        MessageDigest alg = MessageDigest.getInstance(algorithm);
+        alg.update(inputBytes);
+        byte[] digest = alg.digest();
+        outputStr = byte2hex(digest);
+        return outputStr.toUpperCase();
+    }
+
+    public static String sha1(String inStr) throws UnsupportedEncodingException, NoSuchAlgorithmException {
+        String outStr = digest(inStr.getBytes("UTF-8"), "SHA-1");
+        return outStr;
+    }
+
+    public static String sha256(String inStr) throws UnsupportedEncodingException, NoSuchAlgorithmException {
+        String outStr = digest(inStr.getBytes("UTF-8"), "SHA-256");
+        return outStr;
+    }
+
+    public static String md5(String inStr) throws UnsupportedEncodingException, NoSuchAlgorithmException {
+        String outStr = digest(inStr.getBytes("UTF-8"), "MD5");
+        return outStr;
+    }
+
+    public static String encryptBASE64(byte[] key) throws Exception {
+        return Base64.encodeBase64String(key);
+    }
+
+    public static String encryptAES(String source, String secretKey) {
+        try {
+            byte[] sourceBytes = source.getBytes("utf8");
+            SecretKeySpec secretKeySpec = initAESSecretKey(secretKey);
+            byte[] encryptBytes = encrypt(sourceBytes, secretKeySpec);
+            return Base64.encodeBase64URLSafeString(encryptBytes);
+        } catch (Exception var5) {
+            throw new RuntimeException("AES算法加密失败", var5);
+        }
+    }
+
+    private static byte[] encrypt(byte[] source, SecretKeySpec secretKeySpec) throws BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
+        Cipher cipher = Cipher.getInstance(secretKeySpec.getAlgorithm());
+        cipher.init(1, secretKeySpec);
+        return cipher.doFinal(source);
+    }
+
+    public static String encodeBase64String(byte[] source) {
+        return Base64.encodeBase64String(source);
+    }
+}

+ 48 - 59
mall-server-api/src/main/java/com/gree/mall/manager/controller/common/GreeLogic.java

@@ -8,8 +8,11 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.gree.mall.manager.bean.CommonParam;
+import com.gree.mall.manager.bean.OutAppDefaultReq;
 import com.gree.mall.manager.constant.Constant;
 import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.helper.GreeResponseHelper;
 import com.gree.mall.manager.logic.common.CommonLogic;
 import com.gree.mall.manager.utils.RedisUtil;
 import com.gree.mall.manager.utils.http.HttpUtils;
@@ -32,8 +35,9 @@ import java.util.*;
 
 */
 /**
- * 格力总部接口
- *//*
+ * 格力总部接口*//*
+
+
 
 @Slf4j
 @Service
@@ -93,12 +97,13 @@ public class GreeLogic {
         }
     }
 
-    */
+*/
 /**
      * 获取总部接口的请求token
      * @return
-     * @throws RemoteServiceException
-     *//*
+     * @throws RemoteServiceException*//*
+
+
 
     public String getAccessToken() throws RemoteServiceException {
         String redisKey = Constant.RedisPrefix.TOKEN_GREE;
@@ -122,12 +127,13 @@ public class GreeLogic {
         return accessToken;
     }
 
-    */
+*/
 /**
      * 获取总部接口的请求token
      * @return
-     * @throws RemoteServiceException
-     *//*
+     * @throws RemoteServiceException*//*
+
+
 
     public String getAccessTokenV3() throws RemoteServiceException {
         String redisKey = Constant.RedisPrefix.TOKEN_GREE_V3;
@@ -152,36 +158,12 @@ public class GreeLogic {
         return accessToken;
     }
 
-    */
-/**
-     *   获取机型名称
-     * @param objCode 内积条码 或者 外机条码
-     * @param mainNumber 大类id
-     * @return
-     * @throws RemoteServiceException
-     *//*
 
-*/
-/*
-    public CheckBarcodeBean getProductName(String objCode,Integer mainNumber){
-        try {
-            Map<String, Object> map = new HashMap<>();
-            map.put("clientid", clientId);
-            map.put("barcode", objCode);
-            map.put("spid", mainNumber);
-            JSONObject jsonObject = this.post(checkBarcodeUrl, map);
-            CheckBarcodeBean data = JSONObject.parseObject(JSONObject.toJSONString(jsonObject.get("data")), CheckBarcodeBean.class);
-            return data;
-        }catch(Exception e){
-            log.error("获取总部机型失败:"+e.getMessage());
-            return null;
-        }
-    }
-*//*
 
 
 
-    */
+
+*/
 /**
      *   获取销司结算标准
      * @param jxbh 机型编号,条码前五位
@@ -191,6 +173,7 @@ public class GreeLogic {
      * @param spid 大类
      *//*
 
+
     public String getRepairSettle(String jxbh,String wxxmh,String gmrg,String wxlx,String spid){
         try {
             Map<String, Object> map = new HashMap<>();
@@ -211,12 +194,13 @@ public class GreeLogic {
     }
 
 
-    */
+*/
 /**
      *   批量转结算
      * @param ids 多个逗号隔开
      *//*
 
+
     public String doRepairSettle(String ids){
         try {
 
@@ -232,14 +216,14 @@ public class GreeLogic {
         return null;
     }
 
-    */
+*/
 /**
      * 请求总部接口
-     * @return
-     *//*
+     * @return*//*
+
+
 
-  */
-/*  public String post(String apiPath,Map<String,Object> bizContent,Integer belongType) throws Exception {
+  public String post(String apiPath,Map<String,Object> bizContent,Integer belongType) throws Exception {
         CommonParam commonParam = new CommonParam();
         commonParam.setAppId(this.getAppId(belongType));
         commonParam.setAppKey(this.getAppKey(belongType));
@@ -259,7 +243,7 @@ public class GreeLogic {
         }
         return (String)greeResponseHelper.getData();
     }
-    *//*
+
 
     public JSONObject post(String url,List param){
     	Map<String, String> header = new HashMap<>();
@@ -277,13 +261,14 @@ public class GreeLogic {
         return jsonObject;
     }
 
-    */
+*/
 /**
      * post请求,用3.0的token
      * @param url
      * @param param
-     * @return
-     *//*
+     * @return*//*
+
+
 
     public JSONObject postV3(String url,List param){
     	Map<String, String> header = new HashMap<>();
@@ -321,7 +306,7 @@ public class GreeLogic {
         header.put("authorization", "Bearer " + this.getAccessToken());
         log.info("【总部接口对接】request:{}",JSONObject.toJSONString(map));
         JSONObject jsonObject = new JSONObject();
-    	String s = com.gree.settlement.api.utils.HttpUtils.requestPostBodyIO(url, JSONObject.toJSONString(map), header);
+    	String s = HttpUtils.requestPostBodyIO(url, JSONObject.toJSONString(map), header);
         log.info("【总部接口对接】response:{}",s);
         jsonObject = JSONObject.parseObject(s);
 
@@ -340,7 +325,7 @@ public class GreeLogic {
         header.put("authorization", "Bearer " + this.getAccessTokenV3());
         log.info("【总部接口对接】request:{}",JSONObject.toJSONString(map));
         JSONObject jsonObject = new JSONObject();
-    	String s = com.gree.settlement.api.utils.HttpUtils.requestPostBodyIO(url, JSONObject.toJSONString(map), header);
+    	String s = HttpUtils.requestPostBodyIO(url, JSONObject.toJSONString(map), header);
         log.info("【总部接口对接】response:{}",s);
         jsonObject = JSONObject.parseObject(s);
 
@@ -359,7 +344,7 @@ public class GreeLogic {
         header.put("authorization", "Bearer " + this.getAccessTokenV3());
         log.info("【总部接口对接】request:{}",JSONObject.toJSONString(map));
 //        String s = HttpUtils.requestPostBody(url, JSONObject.toJSONString(map), header);
-        String s = com.gree.settlement.api.utils.HttpUtils.requestGet(apiPath+url, map, header);
+        String s = HttpUtils.requestGet(apiPath+url, map, header);
         log.info("【总部接口对接】response:{}",s);
         ObjectMapper mapper = new ObjectMapper();
 		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -401,12 +386,13 @@ public class GreeLogic {
         return jsonObject;
     }
 
-    */
+*/
 /**
      * 同步总部机型名称和单价
      * @param outCode
-     * @param mainNumber
-     *//*
+     * @param mainNumber*//*
+
+
 
     public void syncProduct(String insideCode,String outCode,String mainNumber,Rule rule){
         try {
@@ -500,10 +486,11 @@ public class GreeLogic {
     }
 
 
-    */
+*/
 /**
-     * 初始化机型名称
-     *//*
+     * 初始化机型名称*//*
+
+
 
     public void init(){
         List<ProductNew> list = productNewService.list();
@@ -523,11 +510,12 @@ public class GreeLogic {
         productNewService.updateBatchById(list);
     }
 
-    */
+*/
 /**
      * 请求总部接口
-     * @return
-     *//*
+     * @return*//*
+
+
 
     public GreeResponseHelper greePost(String apiPath,Map<String,Object> bizContent,Integer belongType) throws Exception {
         CommonParam commonParam = new CommonParam();
@@ -573,11 +561,12 @@ public class GreeLogic {
         }
     }
 
-    */
+*/
 /**
      * 请求总部接口
-     * @return
-     *//*
+     * @return*//*
+
+
 
     public GreeResponseHelper greePostDecryptFeed(String apiPath, DecryptFeedbackBean bean) throws Exception {
         Map<String,String> header = new HashMap<>();

+ 13 - 0
mall-server-api/src/main/java/com/gree/mall/manager/helper/GreeResponseHelper.java

@@ -0,0 +1,13 @@
+package com.gree.mall.manager.helper;
+
+
+import lombok.Data;
+
+@Data
+public class GreeResponseHelper<T>  {
+
+    private T data;
+    private String msg;
+    private int status;
+
+}

+ 36 - 2
mall-server-api/src/main/java/com/gree/mall/manager/logic/SyncOrderInfoLogic.java

@@ -8,6 +8,8 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.utils.StringUtils;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.gree.mall.manager.bean.policy.ItfGreeSynDownloadRecBean;
 import com.gree.mall.manager.constant.Constant;
 import com.gree.mall.manager.exception.RemoteServiceException;
@@ -84,11 +86,12 @@ public class SyncOrderInfoLogic {
 
         Long time = itfGreeSynRule.getLastSynTime().getTime()/1000;
 
-        String accessToken = this.getAccessToken();
+        String accessToken = this.getAccessTokenV3();
 
 
         String body = HttpRequest.get(greeUrl+ Constant.gree.GET_UPDATE_ORDERS+"/"+Constant.gree.GUANGZHOUXIAOSI+"/"+time)
-                .header("authorization","Bearer " + accessToken).execute().body();
+                .header("authorization","Bearer " + accessToken)
+                .execute().body();
 
         Map<String,Object> bodyMap = JSON.parseObject(body);
 
@@ -110,9 +113,40 @@ public class SyncOrderInfoLogic {
             ItfGreeSynDownloadRec itfGreeSynDownloadRec = new ItfGreeSynDownloadRec();
         }
 
+    }
+
+
+
+
+    /**
+     * 获取总部接口的请求token
+     * @return
+     * @throws RemoteServiceException
+     */
+    public String getAccessTokenV3() throws RemoteServiceException {
+        String redisKey = Constant.RedisPrefix.TOKEN_GREE_V3;
+        String token = (String)redisUtil.get(redisKey);
+//        if(token != null){
+//            return token;
+//        }
+        MultiValueMap<String, String> forms= new LinkedMultiValueMap<String, String>();
 
+        forms.put("client_id", Collections.singletonList(clientId));
+        forms.put("client_secret", Collections.singletonList(v3ClientSecert));
+
+        forms.put("grant_type", Collections.singletonList("client_credentials"));
+        String s = HttpUtils.requestXwww(v3TokenUrl, forms);
+        //String s = HttpUtils.requestPostForm(tokenUrl, map, null);
+        log.info("【获取总部token】response:{}",s);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        String accessToken = jsonObject.getString("access_token");
+        if(StringUtils.isNotEmpty(accessToken)) {
+            redisUtil.set(Constant.RedisPrefix.TOKEN_GREE_V3, accessToken, 2 * 60 * 60);
+        }
+        return accessToken;
     }
 
+
     /**
      * 获取总部接口的请求token
      * @return

+ 8 - 4
mall-server-api/src/main/java/com/gree/mall/manager/logic/common/CommonLogic.java

@@ -5,6 +5,8 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.TypeReference;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.gree.mall.manager.bean.CommonParam;
+import com.gree.mall.manager.bean.OutAppDefaultReq;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.commonmapper.AdminMapper;
 import com.gree.mall.manager.constant.Constant;
@@ -12,10 +14,7 @@ import com.gree.mall.manager.enums.RedisPrefixEnum;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.plus.entity.*;
 import com.gree.mall.manager.plus.service.*;
-import com.gree.mall.manager.utils.ApplicationContextUtils;
-import com.gree.mall.manager.utils.CommonUtils;
-import com.gree.mall.manager.utils.HttpUtils;
-import com.gree.mall.manager.utils.RedisUtil;
+import com.gree.mall.manager.utils.*;
 import com.gree.mall.manager.utils.oss.OSSUtil;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -620,4 +619,9 @@ public class CommonLogic {
             incrKeyValueService.saveBatch(list);
         }
     }
+
+    public OutAppDefaultReq supplyParam(CommonParam commonParam) throws Exception {
+        OutAppDefaultReq req = SignUtil.getReqParam(commonParam.getAppId(),commonParam.getAppPath(),commonParam.getJson(),commonParam.getAppKey());
+        return req;
+    }
 }

+ 66 - 1
mall-server-api/src/main/java/com/gree/mall/manager/utils/SignUtil.java

@@ -1,8 +1,16 @@
 package com.gree.mall.manager.utils;
 
+import com.gree.mall.manager.bean.OutAppDefaultReq;
+import com.gree.mall.manager.controller.common.CryptTool;
+import org.apache.commons.codec.binary.Base64;
+
+import java.net.URLEncoder;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * Created by Administrator on 2019/5/24 0024.
@@ -67,4 +75,61 @@ public class SignUtil {
         return str;
     }
 
+    public static String bizContent(String jsonObject) throws Exception {
+        String encodedObject = URLEncoder.encode(jsonObject, "UTF-8");
+        encodedObject = encodedObject.replaceAll("\\+", "%20");
+        return CryptTool.encryptBASE64(encodedObject.getBytes("UTF-8"));
+    }
+
+
+    public static OutAppDefaultReq getReqParam(String appid, String apiPath, String bizObject, String appKey) throws Exception {
+        String bizContent = bizContent(bizObject);
+        Timestamp ts = new Timestamp(System.currentTimeMillis());
+        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String timestamp = sdf.format(ts);
+        String version = "V1.0";
+        String rand = StringUtil.getRandomSMS();
+        return OutAppDefaultReq
+                .builder()
+                .appid(appid)
+                .timestamp(timestamp)
+                .signType("SHA256")
+                .sign(getSign(appid,appKey,version,timestamp,bizContent,apiPath,rand))
+                .version(version)
+                .apiPath(apiPath)
+                .bizContent(bizContent)
+                .rand(rand).build();
+    }
+
+
+
+    public static String getSign(String appid, String appKey, String version, String timestamp, String bizContent, String apiPath, String rand) throws Exception {
+        Map<String, Object> map = new HashMap(10);
+        map.put("appid", appid);
+        map.put("version", version);
+        map.put("timestamp", timestamp);
+        map.put("bizContent", bizContent);
+        map.put("apiPath", apiPath);
+        map.put("rand", rand);
+        List<String> list = new ArrayList(map.keySet());
+        Collections.sort(list);
+        StringBuilder builder = new StringBuilder();
+        Iterator var8 = list.iterator();
+        String sign;
+        while(var8.hasNext()) {
+            sign = (String)var8.next();
+            Object value = map.get(sign);
+            if (null != value && !"".equals(value)) {
+                builder.append(sign).append("=").append(value).append("&");
+            }
+        }
+        String content = builder.substring(0, builder.length() - 1);
+        String sha256 = CryptTool.sha256(CryptTool.sha256(content) + appKey);
+        sign = CryptTool.encryptBASE64(sha256.getBytes("UTF-8"));
+        return sign.trim();
+    }
+
+
+
+
 }

+ 342 - 0
mall-server-api/src/main/java/com/gree/mall/manager/utils/sm4/HttpUtils.java

@@ -0,0 +1,342 @@
+package com.gree.mall.manager.utils.sm4;
+
+
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.utils.OkHttpUtil;
+import okhttp3.*;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ *
+ */
+public class HttpUtils {
+
+    private static HttpUtils httpUtils;
+    private OkHttpClient okHttpClient;
+
+    @Value("${web.imageService}")
+    private static String wanPath;
+
+    private final static Logger logger = LoggerFactory.getLogger(HttpUtils.class);
+
+    private HttpUtils() {
+        okHttpClient = new OkHttpClient();
+        okHttpClient.newBuilder().
+                connectTimeout(100, TimeUnit.SECONDS).
+                readTimeout(200, TimeUnit.SECONDS)
+                .writeTimeout(100, TimeUnit.SECONDS);
+
+    }
+
+    //创建 单例模式(OkHttp官方建议如此操作)
+    public static HttpUtils getInstance() {
+        if (httpUtils == null) {
+            httpUtils = new HttpUtils();
+        }
+        return httpUtils;
+    }
+
+    static private Request.Builder getGetBuilder(String url, Map<String, String> params, Map<String, String> heads) {
+        Request.Builder reqBuild = new Request.Builder();
+        HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
+
+        if (params != null) {
+            for (String key : params.keySet()) {
+                urlBuilder.addQueryParameter(key, params.get(key));
+            }
+        }
+
+
+        reqBuild.url(urlBuilder.build());
+        if (heads != null) {
+            for (String key : heads.keySet()) {
+                reqBuild.addHeader(key, heads.get(key));
+            }
+        }
+
+        return reqBuild;
+    }
+
+
+
+
+
+
+    static public String requestGet(String url, Map<String, String> params, Map<String, String> heads) throws RemoteServiceException {
+        Request.Builder reqBuild = getGetBuilder(url, params, heads);
+        Request req = reqBuild.build();
+
+        try {
+            Response response = OkHttpUtil.execute(req);
+            //判断请求是否成功
+            if (response.isSuccessful()) {
+                String content = response.body().string();
+                return content;
+                //打印服务端返回结果
+            } else {
+                throw new RemoteServiceException(response.code(), response.message());
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error(HttpUtils.class.getName(), e);
+            throw new RemoteServiceException(505, e.getMessage());
+        }
+    }
+
+    static public String requestGetYB(String url, Map<String, String> params, Map<String, String> heads, Callback callback) {
+        Request.Builder reqBuild = getGetBuilder(url, params, heads);
+        Request req = reqBuild.build();
+
+        try {
+            OkHttpUtil.enqueue(req, callback);
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error(HttpUtils.class.getName(), e);
+        }
+        return "ok";
+    }
+
+
+    static private Request.Builder getBodyBuilder(String url, String json, Map<String, String> heads) {
+        logger.info("requestPostBody url:" + url);
+        logger.info("body:" + json);
+        MediaType JSONType = MediaType.parse("application/json; charset=utf-8");
+        RequestBody body = RequestBody.create(JSONType, json);
+        Request.Builder builder = new Request.Builder();
+
+        builder.url(url);
+
+        if (heads != null) {
+            for (String key : heads.keySet()) {
+
+                builder.addHeader(key, heads.get(key));
+            }
+        }
+        builder.post(body);
+        return builder;
+    }
+
+    static private Request.Builder getFormBuilder(String url, Map<String, String> params, Map<String, String> heads) {
+        FormBody.Builder bodyBuilder = new FormBody.Builder();
+
+        logger.info("form url:" + url);
+        logger.info("params:" + params.toString());
+
+        try {
+            if (params != null) {
+                for (String key : params.keySet()) {
+                    if (StringUtils.isNotEmpty(params.get(key))) {
+                        bodyBuilder.add(key, params.get(key));
+                    } else {
+                        bodyBuilder.add(key, "");
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println(e);
+        }
+
+        RequestBody body = bodyBuilder.build();
+        Request.Builder builder = new Request.Builder();
+
+        if (heads != null) {
+            for (String key : heads.keySet()) {
+
+                builder.addHeader(key, heads.get(key));
+            }
+        }
+        builder.url(url);
+        builder.post(body);
+
+        return builder;
+
+    }
+
+
+    static public String requestPostBody(String url, String json, Map<String, String> heads) throws RemoteServiceException {
+
+
+        Request.Builder builder = getBodyBuilder(url,json,heads);
+        Request req = builder.build();
+
+        try {
+            Response response = OkHttpUtil.execute(req);
+            logger.error(response.toString());
+            if (response.isSuccessful()) {
+                String returnString = response.body().string();
+                return returnString;
+                //打印服务端返回结果
+
+            } else {
+
+                logger.error("failure: " + response.body().string());
+
+                throw new RemoteServiceException(response.code(), response.message());
+            }
+            //throw   new ApiException(response.code(),response.body().string());
+        } catch (Exception e) {
+            logger.error(HttpUtils.class.getName(), e);
+            throw new RemoteServiceException(505, e.getMessage());
+        }
+
+
+    }
+    
+    static public String requestPostBodyIO(String url, String json, Map<String, String> heads) throws  IOException {
+//    	logger.info("requestPostBody url:" + url);
+//    	logger.info("body:" + json);
+//        MediaType JSONType = MediaType.parse("application/json; charset=utf-8");
+//        RequestBody body = RequestBody.create(JSONType, json);
+//        Request.Builder builder = new Request.Builder();
+//        builder.url(url);
+//        if (heads != null) {
+//            for (String key : heads.keySet()) {
+//                builder.addHeader(key, heads.get(key));
+//            }
+//        }
+//        builder.post(body);
+        Request.Builder builder = getBodyBuilder(url,json,heads);
+        Request req = builder.build();
+//        try {
+            Response response = OkHttpUtil.execute(req);
+            
+            logger.error(response.toString());
+            return response.body().string();
+//            String returnString = response.body().string();
+//            if (response.isSuccessful()) {
+////                String returnString = response.body().string();
+//                return returnString;
+//            } else {
+//                return returnString;
+//            }
+
+    }
+    
+
+    static public String requestPostBodyYB(String url, String json, Map<String, String> heads, Callback cb) {
+        Request.Builder builder = getBodyBuilder(url,json,heads);
+        Request req = builder.build();
+        try {
+            OkHttpUtil.enqueue(req, cb);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    static public String requestPostForm(String url, Map<String, String> params, Map<String, String> heads) throws RemoteServiceException {
+
+
+
+        Request.Builder builder = getFormBuilder(url,params,heads);
+
+        Request req = builder.build();
+
+        try {
+            Response response = OkHttpUtil.execute(req);
+            if (response.isSuccessful()) {
+                return response.body().string();
+            } else {
+                throw new RemoteServiceException(response.code(), response.message());
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RemoteServiceException(505, e.getMessage());
+        }
+    }
+
+    static public String requestPostFormYB(String url, Map<String, String> params, Map<String, String> heads, Callback cb) {
+
+        Request.Builder builder = getFormBuilder(url,params,heads);
+        Request req = builder.build();
+        try {
+            OkHttpUtil.enqueue(req, cb);
+            //打印服务端返回结果
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "";
+
+    }
+
+    public String downloadFile(String path, String url, String json, Map<String, String> heads){
+
+        MediaType JSONType = MediaType.parse("application/json; charset=utf-8");
+        RequestBody body = RequestBody.create(JSONType, json);
+        Request.Builder builder = new Request.Builder();
+        builder.url(url);
+        if (heads != null) {
+            for (String key : heads.keySet()) {
+                builder.addHeader(key, heads.get(key));
+            }
+        }
+
+        builder.post(body);
+        Request req = builder.build();
+
+
+        InputStream is = null;
+        FileOutputStream fos = null;
+        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
+        String dateString = df.format(new Date());
+        String newFilePath = path + "/upload/miniqrcode/" + dateString + "/";
+        String newFileName = new Date().getTime() + ".png";
+        File checkFile = new File(newFilePath);
+        if (!checkFile.exists() && !checkFile.isDirectory()) {
+            checkFile.mkdirs();
+        }
+
+        try {
+            Response response = okHttpClient.newCall(req).execute();
+            if (response.isSuccessful()) {
+                byte[] buf = new byte[1024];
+                int len = 0;
+                is = response.body().byteStream();
+                File file = new File(newFilePath, newFileName);
+
+                fos = new FileOutputStream(file);
+                while ((len = is.read(buf)) != -1) {
+                    fos.write(buf, 0, len);
+                }
+                fos.flush();
+                //如果下载文件成功,第一个参数为文件的绝对路径
+            } else {
+                return null;
+            }
+        } catch (IOException e) {
+            System.out.println("数据获取失败");
+        } finally {
+            try {
+                if (is != null)
+                    is.close();
+            } catch (IOException e) {
+            }
+            try {
+                if (fos != null)
+                    fos.close();
+            } catch (IOException e) {
+            }
+        }
+
+        return "/miniqrcode/" + dateString + "/" + newFileName;
+
+    }
+
+//    新创建积分商品二维码路径
+
+
+}