| 
					
				 | 
			
			
				@ -0,0 +1,73 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.wlyy.wlyyhttp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.wlyyinfo.OauthWlyyConfigDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.http.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wlyy.dao.OauthWlyyConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.collections.map.HashedMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.NameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.message.BasicNameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Trick on 2019/8/19. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class WlyyHttpService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final Logger logger = LoggerFactory.getLogger(WlyyHttpService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OauthWlyyConfigDao oauthWlyyConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private HttpClientUtil httpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject sendWlyyMes(String configId,JSONObject param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OauthWlyyConfigDO oauthWlyyConfigDO = oauthWlyyConfigDao.findOne(configId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //token获取accesstoken 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<NameValuePair> params = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(new BasicNameValuePair("appid", oauthWlyyConfigDO.getAppId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        params.add(new BasicNameValuePair("appSecret", oauthWlyyConfigDO.getAppSecret())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String res = httpClientUtil.post(oauthWlyyConfigDO.getTokenUrl(), params, "UTF-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String token = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject rsjson = JSONObject.parseObject(res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("sendWlyyMes token :" + rsjson.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer status = rsjson.getInteger("status"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (status == 10000) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //设置入参 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<NameValuePair> p = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            p.add(new BasicNameValuePair("param", param.toJSONString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //设置头部 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            token = rsjson.getJSONObject("result").getString("accesstoken"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String,Object> headerMap = new HashedMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            headerMap.put("accesstoken",token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String rs = httpClientUtil.headerPost(oauthWlyyConfigDO.getUrl(),p,"UTF-8",headerMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("sendWlyyMes headerPost :"+rs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject auth = JSONObject.parseObject(rs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer s = auth.getInteger("status"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(s == 200){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject data = auth.getJSONObject("data"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |