java拼接url



import javax.servlet.http.HttpUtils;

public class test {
public static void main(String[] args) {
	String name="aa";
	String password="sdads";
	StringBuffer url=new StringBuffer();
	url.append("www.baidu.com?");
	url.append("name=").append(name);
	url.append("&").append("password").append(password);
	System.out.println(url.toString());
}
}

2

import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yiyun.entity.Order;
import com.yiyun.entity.vo.Order_uc;
import com.yiyun.services.wx.OrderAndUserServices;
import com.yiyun.util.HttpRequest;
import com.yiyun.util.WXPayUtil;



System.out.println("code="+code);
			String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="
					             +  appID + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
			System.out.println(url);
			HttpClient client = new DefaultHttpClient();
			HttpPost post = new HttpPost(url);
			HttpResponse res = client.execute(post);
			Map map=new HashMap();
			if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				HttpEntity entity = res.getEntity();
				String str = EntityUtils.toString(entity, "utf-8");
				ObjectMapper mapper=new ObjectMapper();
				Map<String,Object> jsonOb=mapper.readValue(str, Map.class);
				System.out.println(jsonOb);
				//list.add(jsonOb.get("access_token"));
				//list.add(jsonOb.get("openid"));
			String openid=(String) jsonOb.get("openid");
			String access_token=(String) jsonOb.get("access_token");
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值