OkHttp + Gson

Gson gson =newGson();

OkHttpClient client =newOkHttpClient();

// http://kaifa.huandengpai.com/ajax/pay/wxpay/api/preorder?nid=1&price=0.01&description=aaa&tag=recharge

Request req =newRequest.Builder()

.url("http://kaifa.huandengpai.com/ajax/pay/wxpay/api/preorder?nid=1&price=0.01&description=aaa&tag=recharge")

.build();

Response res =null;

try{

res = client.newCall(req).execute();

if(res.isSuccessful()) {

WxPay wxPay = gson.fromJson(res.body().charStream(),WxPay.class);

String appId = wxPay.getData().getAppid();

String partnerId = wxPay.getData().getPartnerid();

String prepayId = wxPay.getData().getPrepayid();

String nonceStr = wxPay.getData().getNoncestr();

String sign = wxPay.getData().getSign();

String timeStamp = String.valueOf(wxPay.getData().getTimestamp());

PayReq request =newPayReq();

request.appId= appId;

request.partnerId= partnerId;

request.prepayId= prepayId;

request.packageValue="Sign=WXPay";

request.nonceStr= nonceStr;

request.timeStamp= timeStamp;

request.sign= sign;

msgApi.sendReq(request);

}

}catch(IOException e) {

e.printStackTrace();

}

}

}).start();

你可能感兴趣的:(OkHttp + Gson)