Java使用HTTPClient调用远程URL实例

  • Post author:
  • Post category:java


案例描述:一次项目中后端服务需要从微信小程序获取扫码关注次数,网上搜各种示例都不太好用(代码冗余且效果不佳),于是自己花功夫做了一套。

public interface CustomerAppointAPIService {
   

	String getApiToken(JSONObject json);
	
	JSONObject getFollowNum(JSONObject SaleId);

	void updateFacoriteCountRealitys();
}
package com.faw.xxx.modules.staff.service.impl;

import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.faw.xxx.modules.staff.dao.DsCepStaffDAO;
import com.faw.xxx.modules.staff.entity.DsCepStaff;
import com.faw.xxx.modules.staff.service.CustomerAppointAPIService;
import com.faw.xxx.utils.SSLClient;

import cn.hutool.core.codec.Base64;

@Service
public class CustomerAppointAPIServiceImpl implements CustomerAppointAPIService {
   

	@Autowired
	private DsCepStaffDAO dsCepStaffDAO;
	/**
	 * 授权接口
	 * 参数格式:
	 *{
	 *	"Client":"digital_xxx",//客户端标识
	 *	"Secret":"@-!xxx"//客户端接入秘钥
	 *}
	 */
	@Override
	public String getApiToken(JSONObject json) {
   
		HttpClient httpClient = null;
    



版权声明:本文为kongfangzi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。