您的位置:首页 > 移动开发 > 微信开发

android 微信支付 签名错误

2016-08-17 13:21 246 查看

前言

最近在做一个web app是个商城里面需要集成微信支付,在开发的过程中遇到许多坑。
本次主要介绍签名错误,其实造成签名的错误有很多。

正文 

我这里只介绍 由于网络请求参数StringEntity编码错误造成的签名错误。StringEntity 使用ISO8859-1编码就可以了。
代码如下
public static String httpPost(String url, String entity) {
String result = "";
//HttpClient client = HttpClients.createDefault();
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
//httpPost.setEntity(new StringEntity(entity));
httpPost.setEntity(new StringEntity(new String(entity.getBytes(), "ISO8859-1")));
HttpResponse httpResponse = client.execute(httpPost);
//否则会乱码
result = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
}
catch (IOException e) {
e.printStackTrace();
}
return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: