本人开发的开发者技术变现资源聚集地,大家支持下,下面是网址
https://www.baiydu.com
如果就直接将JSON作为请求字符串,服务端会出现中文乱码。所以只需要将请求的整个JSON参数字符串编码一次,然后服务端解码一次。我这里服务端使用的servlet,下面会两段代码贴出。
android:
String url = customSessionSingleton.getInstance().requestBaseUrl+"AlipayInterface"; try { OkHttpUtils.post().url(url).addParams("masterParameter", URLEncoder.encode(passSessionData.toString(), "UTF-8")) .build().execute(new StringCallback() { @Override public void onBefore(Request request, int id) { } @Override public void onAfter(int id) { } @Override public void onError(Call call, Exception e, int id) { e.printStackTrace(); String json= e.getMessage(); } @Override public void onResponse(String response, int id) { JSONObject returnJSONObject = null; try { returnJSONObject=new JSONObject(response) ; if(returnJSONObject.getInt( "Success" )==1) { if(payWay.equals( "支付宝" )) { serverSignStr=serverSignStr+"&sign=" + returnJSONObject.getString( "sign" ); Runnable payRunnable = new Runnable() { @Override public void run() { PayTask alipay = new PayTask(HomeFragment_RechargeActivity.this); Map<String, String> result = alipay.payV2(serverSignStr, true); Log.i("msp", result.toString()); Message msg = new Message(); msg.what = SDK_PAY_FLAG; msg.obj = result; alipayHandle.sendMessage(msg); } }; Thread payThread = new Thread(payRunnable); payThread.start(); } else if(payWay.equals( "微信" )) { } else if(payWay.equals( "全积分抵扣" )) { Dialog alertDialog = new AlertDialog.Builder(HomeFragment_RechargeActivity.this). setTitle("登录用户,全积分抵扣"). setMessage("全积分抵扣"). setIcon(R.drawable.ic_launcher). create(); alertDialog.show(); mLoading.dismiss(); } } else { } } catch (JSONException e) { e.printStackTrace(); } } }); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }
Servlet:
JSONObject requestObject=new JSONObject(URLDecoder.decode(request.getParameter("masterParameter"),"utf-8")); String account= requestObject.getString("account");
本人创业做的一款androidApp, 下载量已经有2000多万,各种当前热门的网络手机奖励红包全部集成,另外还有热门电影和淘宝高额优惠券!很适合各类型的用户。