use of com.lzy.okgo.callback.StringCallback in project RxTools by vondear.
the class WechatPayTools method wechatPayUnifyOrder.
/**
* 商户发起生成预付单请求
*
* @return
*/
public static String wechatPayUnifyOrder(final Context mContext, final String appid, final String mch_id, final String wx_private_key, WechatModel wechatModel, final OnSuccessAndErrorListener OnSuccessAndErrorListener) {
// 随机码
String nonce_str = getRandomStringByLength(8);
// 商品描述
String body = wechatModel.getDetail();
// 商品订单号
String out_trade_no = wechatModel.getOut_trade_no();
// 商品编号
String product_id = wechatModel.getOut_trade_no();
// 总金额 分
String total_fee = wechatModel.getMoney();
// 交易起始时间(订单生成时间非必须)
String time_start = getCurrTime();
// App支付
String trade_type = "APP";
// "http://" + "域名" + "/" + "项目名" + "回调地址.do";//回调函数
String notify_url = "https://github.com/tamsiree/RxTool";
SortedMap<String, String> params = new TreeMap<String, String>();
params.put("appid", appid);
params.put("mch_id", mch_id);
// 设备号
params.put("device_info", "WEB");
params.put("nonce_str", nonce_str);
// 商品描述
params.put("body", body);
params.put("out_trade_no", out_trade_no);
params.put("product_id", product_id);
params.put("total_fee", total_fee);
params.put("time_start", time_start);
params.put("trade_type", trade_type);
params.put("notify_url", notify_url);
// 签名(该签名本应使用微信商户平台的API证书中的密匙key,但此处使用的是微信公众号的密匙APP_SECRET)
String sign = "";
sign = getSign(params, wx_private_key);
// 参数xml化
String xmlParams = parseString2Xml(params, sign);
// 判断返回码
final String[] jsonStr = { "" };
OkGo.<String>post(WX_TOTAL_ORDER).upString(xmlParams).execute(new StringCallback() {
@Override
public void onSuccess(com.lzy.okgo.model.Response<String> response) {
String s = response.body();
TLog.d("微信统一下单", s);
jsonStr[0] = s;
Map<String, String> mapXml = null;
try {
mapXml = getMapFromXML(s);
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
}
String time = getCurrTime();
SortedMap<String, String> params = new TreeMap<String, String>();
params.put("appid", appid);
params.put("noncestr", "5K8264ILTKCH16CQ2502SI8ZNMTM67VS");
params.put("package", "Sign=WechatPay");
params.put("partnerid", mch_id);
params.put("prepayid", mapXml.get("prepay_id"));
params.put("timestamp", time);
wechatPayApp(mContext, appid, mch_id, wx_private_key, params, OnSuccessAndErrorListener);
}
});
if (!jsonStr[0].contains("FAIL") && jsonStr[0].trim().length() > 0) {
// 成功
return "success";
} else {
// 失败
return "fail";
}
}
use of com.lzy.okgo.callback.StringCallback in project cuddly-octo-fortnight by prpr894.
the class LiveRoomListActivity method initData.
private void initData() {
if (!isRefresh) {
showProgress("加载中...", false);
}
String baseUrl;
if (SPUtil.getBoolen(MyApp.getInstance(), "defaultBase", true)) {
baseUrl = SPUtil.getString(MyApp.getInstance(), "baseUrlFromServer", "http://ww.jiafangmao.com/6");
} else {
baseUrl = SPUtil.getString(MyApp.getInstance(), "customBase", "http://ww.jiafangmao.com/3");
}
final String baseUrlStr = baseUrl;
OkGo.<String>get(baseUrl + data.getUrl()).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
Log.d("flag", "返回的房间列表: " + response.body());
hideProgress();
mSmartRefreshLayout.finishRefresh();
try {
JSONObject object = new JSONObject(response.body());
if (object.has("data")) {
Gson gson = new Gson();
List<LiveRoomItemDataBean> data = gson.fromJson(response.body(), LiveRoomListBean.class).getData();
mAdapter.removeAll();
mAdapter.addAll(data);
} else {
MyToast.error("数据异常!");
}
} catch (JSONException e) {
e.printStackTrace();
MyToast.warn("数据异常!");
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
Log.d("flag", baseUrlStr + " code: " + response.code());
MyToast.error("网络连接异常!");
hideProgress();
mSmartRefreshLayout.finishRefresh();
}
});
}
use of com.lzy.okgo.callback.StringCallback in project cuddly-octo-fortnight by prpr894.
the class ChangeBaseRecyclerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mTextViewUrl.setText(String.format(Locale.getDefault(), "源 %03d", position + 1));
choiseJianCeZhong(holder);
//
OkGo.<String>head(mList.get(position) + "/xyjk.html").execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
Log.d("flag", mList.get(position) + "/xyjk.html code: " + response.code());
if (response.code() == 200) {
choiceXuanZe(holder);
} else {
choiceBuKeYong(holder);
}
checkDefault(position, holder);
}
@Override
public void onError(Response<String> response) {
super.onError(response);
choiceBuKeYong(holder);
checkDefault(position, holder);
}
});
}
use of com.lzy.okgo.callback.StringCallback in project okhttp-OkGo by jeasonlzy.
the class RxFormUploadActivity method formUpload2.
@OnClick(R.id.formUpload2)
public void formUpload2(View view) {
final ArrayList<File> files = new ArrayList<>();
if (imageItems != null && imageItems.size() > 0) {
for (int i = 0; i < imageItems.size(); i++) {
files.add(new File(imageItems.get(i).path));
}
}
Observable.create(new ObservableOnSubscribe<Progress>() {
@Override
public void subscribe(@NonNull final ObservableEmitter<Progress> e) throws Exception {
//
OkGo.<String>post(Urls.URL_FORM_UPLOAD).tag(//
this).headers("header1", //
"headerValue1").headers("header2", //
"headerValue2").params("param1", //
"paramValue1").params("param2", //
"paramValue2").addFileParams("file", //
files).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
e.onComplete();
}
@Override
public void onError(Response<String> response) {
e.onError(response.getException());
}
@Override
public void uploadProgress(Progress progress) {
e.onNext(progress);
}
});
}
}).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
btnFormUpload2.setText("正在上传中...");
}
}).observeOn(//
AndroidSchedulers.mainThread()).subscribe(new Observer<Progress>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
addDisposable(d);
}
@Override
public void onNext(@NonNull Progress progress) {
System.out.println("uploadProgress: " + progress);
String downloadLength = Formatter.formatFileSize(getApplicationContext(), progress.currentSize);
String totalLength = Formatter.formatFileSize(getApplicationContext(), progress.totalSize);
tvDownloadSize.setText(downloadLength + "/" + totalLength);
String speed = Formatter.formatFileSize(getApplicationContext(), progress.speed);
tvNetSpeed.setText(String.format("%s/s", speed));
tvProgress.setText(numberFormat.format(progress.fraction));
pbProgress.setMax(10000);
pbProgress.setProgress((int) (progress.fraction * 10000));
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace();
btnFormUpload2.setText("上传出错");
showToast(e.getMessage());
}
@Override
public void onComplete() {
btnFormUpload2.setText("上传完成");
}
});
}
use of com.lzy.okgo.callback.StringCallback in project RxTools by vondear.
the class WechatPayTools method wechatPayUnifyOrder.
/**
* 商户发起生成预付单请求
*
* @return
*/
public static String wechatPayUnifyOrder(final Context mContext, final String appid, final String mch_id, final String wx_private_key, WechatModel wechatModel, final OnRequestListener OnRequestListener) {
// 随机码
String nonce_str = getRandomStringByLength(8);
// 商品描述
String body = wechatModel.getDetail();
// 商品订单号
String out_trade_no = wechatModel.getOut_trade_no();
// 商品编号
String product_id = wechatModel.getOut_trade_no();
// 总金额 分
String total_fee = wechatModel.getMoney();
// 交易起始时间(订单生成时间非必须)
String time_start = getCurrTime();
// App支付
String trade_type = "APP";
// "http://" + "域名" + "/" + "项目名" + "回调地址.do";//回调函数
String notify_url = "https://github.com/vondear/RxTools";
SortedMap<String, String> params = new TreeMap<String, String>();
params.put("appid", appid);
params.put("mch_id", mch_id);
// 设备号
params.put("device_info", "WEB");
params.put("nonce_str", nonce_str);
// 商品描述
params.put("body", body);
params.put("out_trade_no", out_trade_no);
params.put("product_id", product_id);
params.put("total_fee", total_fee);
params.put("time_start", time_start);
params.put("trade_type", trade_type);
params.put("notify_url", notify_url);
// 签名(该签名本应使用微信商户平台的API证书中的密匙key,但此处使用的是微信公众号的密匙APP_SECRET)
String sign = "";
sign = getSign(params, wx_private_key);
// 参数xml化
String xmlParams = parseString2Xml(params, sign);
// 判断返回码
final String[] jsonStr = { "" };
OkGo.<String>post(WX_TOTAL_ORDER).upString(xmlParams).execute(new StringCallback() {
@Override
public void onSuccess(com.lzy.okgo.model.Response<String> response) {
String s = response.body();
Log.d("微信统一下单", s);
jsonStr[0] = s;
Map<String, String> mapXml = null;
try {
mapXml = getMapFromXML(s);
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
}
String time = getCurrTime();
SortedMap<String, String> params = new TreeMap<String, String>();
params.put("appid", appid);
params.put("noncestr", "5K8264ILTKCH16CQ2502SI8ZNMTM67VS");
params.put("package", "Sign=WechatPay");
params.put("partnerid", mch_id);
params.put("prepayid", mapXml.get("prepay_id"));
params.put("timestamp", time);
wechatPayApp(mContext, appid, mch_id, wx_private_key, params, OnRequestListener);
}
});
if (!jsonStr[0].contains("FAIL") && jsonStr[0].trim().length() > 0) {
// 成功
return "success";
} else {
// 失败
return "fail";
}
}
Aggregations