android app 获取paypal PaymentDetails

 

try {
	HttpClient httpclient = new DefaultHttpClient();
	HttpPost httppost = null;
	httppost = new HttpPost("https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails");
					
	httppost.setHeader("Content-Type","application/x-www-form-urlencoded");
	httppost.setHeader("X-PAYPAL-SECURITY-USERID","username");//填入用户名
	httppost.setHeader("X-PAYPAL-SECURITY-PASSWORD","passowrd");//密码
	httppost.setHeader("X-PAYPAL-SECURITY-SIGNATURE","signature");//证书
	httppost.setHeader("X-PAYPAL-APPLICATION-ID","APP-80W284485P519543T");//沙盒app id,正式环境中需替换成相应的app id
	httppost.setHeader("X-PAYPAL-REQUEST-DATA-FORMAT", "nv");
	httppost.setHeader("X-PAYPAL-RESPONSE-DATA-FORMAT", "nv");

	List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
	nameValuePairs.add(new BasicNameValuePair("payKey", transID));
	nameValuePairs.add(new BasicNameValuePair("requestEnvelope.errorLanguage", "en_US"));

	httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
	HttpResponse response = httpclient.execute(httppost);
	HttpEntity entity = response.getEntity();
	InputStream is = entity.getContent();
	byte[] data1;
	data1 = new byte[256];
	StringBuffer buffer = new StringBuffer();
	int len = 0;
	while (-1 != (len = is.read(data1))) {
		buffer.append(new String(data1, 0, len));
		}
		System.out.println("--------->" + buffer.toString());
	is.close();
} catch (Exception e) {
	Log.e("", "error " + e);
}

大家得把以上的 用户、密码、证书替换成自己相应的信息

以上System.out.println("--------->" + buffer.toString());就是Paypal付款成功后返回的详细信息,包括交易id;但出于安全的考虑,不建议在客户端执行该步骤,由于要执行该步骤,客户端程序需要paypal证书等一系列信息,如果把证书啥写进代码,这样子会存在一定的风险,这也是Paypal不建议这么做的原因(有了paykey可以获取到更多的信息,比如详细地址等等)。


 
 

你可能感兴趣的:(android,exception,String,buffer,byte)