本文整理汇总了Java中com.alibaba.fastjson.JSONObject.toJSONString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.toJSONString方法的具体用法?Java JSONObject.toJSONString怎么用?Java JSONObject.toJSONString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toJSONString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMusic
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 发送音乐消息
* {
* "touser":"OPENID",
* "msgtype":"music",
* "music":
* {
* "title":"MUSIC_TITLE",
* "description":"MUSIC_DESCRIPTION",
* "musicurl":"MUSIC_URL",
* "hqmusicurl":"HQ_MUSIC_URL",
* "thumb_media_id":"THUMB_MEDIA_ID"
* }
* }
*
* @param music 音乐消息
*/
public void sendMusic(MusicResponse music) {
this.msgType = MsgType.music.name();
JSONObject jsonMsg = new JSONObject();
jsonMsg.put("title", music.getTitle());
jsonMsg.put("description", music.getDescription());
jsonMsg.put("musicurl", music.getMusicURL());
jsonMsg.put("hqmusicurl", music.getHQMusicUrl());
jsonMsg.put("thumb_media_id", music.getThumbMediaId());
JSONObject json = new JSONObject();
json.put("touser", this.toUserOpenId);
json.put("msgtype", this.msgType);
json.put("music", jsonMsg);
this.msgBody = json.toJSONString();
send();
}
示例2: __buildJsApiConfigStr
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private String __buildJsApiConfigStr(String appId, String jsapiTicket, String url, String timestamp, String noncestr, boolean debug) throws Exception {
String _signature = "jsapi_ticket=" + jsapiTicket + "&" + "noncestr=" + noncestr + "&" + "timeStamp=" + timestamp + "&" + "url=" + url;
_signature = DigestUtils.sha1Hex(_signature);
//
JSONObject _json = new JSONObject();
_json.put("debug", debug);
_json.put("appId", appId);
_json.put("timestamp", timestamp);
_json.put("nonceStr", noncestr);
_json.put("signature", _signature);
_json.put("jsApiList", new String[]{"chooseWXPay"});
//
return _json.toJSONString();
}
示例3: postJson
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/** post
* @param url 请求的url
* @param queries 请求的参数,在浏览器?后面的数据,没有可以传null
* @param obj post obj 提交json
* @return
* @throws IOException
*/
public <T> String postJson(String url, Map<String, String> queries, T obj) throws IOException {
String responseBody = "";
CloseableHttpClient httpClient = getHttpClient();
StringBuilder sb = new StringBuilder(url);
appendQueryParams(queries, sb);
//指定url,和http方式
HttpPost httpPost = new HttpPost(sb.toString());
if (SetTimeOut) {
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(SocketTimeout)
.setConnectTimeout(ConnectTimeout).build();//设置请求和传输超时时间
httpPost.setConfig(requestConfig);
}
//添加参数
String jsonbody = null;
if (obj != null) {
jsonbody = JSONObject.toJSONString(obj);
}
//设置参数到请求对象中
StringEntity stringEntity = new StringEntity(jsonbody,"utf-8");//解决中文乱码问题
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
//请求数据
CloseableHttpResponse response = httpClient.execute(httpPost);
responseBody = getResponseString(responseBody, response);
return responseBody;
}
示例4: pay
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@RequestMapping(value = "/pay/{goodsOrderId}", method = RequestMethod.GET)
@ResponseBody
public String pay(@PathVariable("goodsOrderId") String goodsOrderId) {
GoodsOrder goodsOrder = goodsOrderService.getGoodsOrder(goodsOrderId);
if(goodsOrder == null) return "fail";
int status = goodsOrder.getStatus();
if(status != Constant.GOODS_ORDER_STATUS_INIT) {
return "fail_001";
}
JSONObject paramMap = new JSONObject();
paramMap.put("mchId", mchId); // 商户ID
paramMap.put("mchOrderNo", goodsOrderId); // 商户订单号
paramMap.put("channelId", "ALIPAY_WAP"); // 支付渠道ID, WX_NATIVE,ALIPAY_WAP
paramMap.put("amount", goodsOrder.getAmount()); // 支付金额,单位分
paramMap.put("currency", "cny"); // 币种, cny-人民币
paramMap.put("clientIp", "114.112.124.236"); // 用户地址,IP或手机号
paramMap.put("device", "WEB"); // 设备
paramMap.put("subject", goodsOrder.getGoodsName());
paramMap.put("body", goodsOrder.getGoodsName());
paramMap.put("notifyUrl", "http://shop.xxpay.org/goods/payNotify"); // 回调URL
paramMap.put("param1", ""); // 扩展参数1
paramMap.put("param2", ""); // 扩展参数2
paramMap.put("extra", "{\"productId\":\"120989823\",\"openId\":\"o2RvowBf7sOVJf8kJksUEMceaDqo\"}"); // 附加参数
String reqSign = PayDigestUtil.getSign(paramMap, reqKey);
paramMap.put("sign", reqSign); // 签名
String reqData = "params=" + paramMap.toJSONString();
System.out.println("请求支付中心下单接口,请求数据:" + reqData);
String url = baseUrl + "/pay/create_order?";
String result = XXPayUtil.call4Post(url + reqData);
System.out.println("请求支付中心下单接口,响应数据:" + result);
Map retMap = JSON.parseObject(result);
if("SUCCESS".equals(retMap.get("retCode"))) {
// 验签
String checkSign = PayDigestUtil.getSign(retMap, resKey, "sign", "payParams");
String retSign = (String) retMap.get("sign");
if(checkSign.equals(retSign)) {
System.out.println("=========支付中心下单验签成功=========");
}else {
System.err.println("=========支付中心下单验签失败=========");
return null;
}
}
String payOrderId = retMap.get("payOrderId").toString();
goodsOrder = new GoodsOrder();
goodsOrder.setGoodsOrderId(goodsOrderId);
goodsOrder.setPayOrderId(payOrderId);
goodsOrder.setChannelId("ALIPAY_WAP");
int ret = goodsOrderService.update(goodsOrder);
_log.info("修改商品订单,返回:{}", ret);
return result+"";
}
示例5: buildRequestParams
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
protected AsyncRequest buildRequestParams() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("vfwebqq", session.getVfwebqq());
jsonObject.put("hash", WqqEncryptor.hash(String.valueOf(session.getUin()), session.getPtwebqq()));
Parameters params = new Parameters("r", jsonObject.toJSONString());
Headers headers = new Headers("Referer", RequestUrls.referer_common.url);
return new AsyncRequest(RequestUrls.get_group_name_list_mask2.url, HttpMethod.post, params, headers);
}
示例6: sendTextMsg
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 发送文字消息,
*
* @param touser
* 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
* @param toparty
* 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数s
* @param totag
* 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
* @param agentid
* 企业应用的id,整型。可在应用的设置页面查看
* @param content
* 消息内容
* @param safe
* 表示是否是保密消息,0表示否,1表示是,默认0
* @throws IOException
*/
public static String sendTextMsg(String touser, String toparty, String totag, int agentid, String content,
boolean safe) throws IOException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("touser", touser);// 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
jsonObject.put("toparty", toparty);// 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
jsonObject.put("totag", totag);// 标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
jsonObject.put("agentid", agentid + "");// 企业应用的id,整型。可在应用的设置页面查看
jsonObject.put("msgtype", "text");// 消息类型,此时固定为:text
JSONObject text = new JSONObject();
text.put("content", content);
jsonObject.put("text", text);// 消息内容
if (safe) {
jsonObject.put("safe", "1");// 表示是否是保密消息,0表示否,1表示是,默认0
} else {
jsonObject.put("safe", "0");// 表示是否是保密消息,0表示否,1表示是,默认0
}
String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="
+ WeiXinCompanyUtils.getToken();
String parameters = jsonObject.toJSONString();
reSend(urlStr, parameters, new HashMap<String, Integer>());
return "";
}
示例7: H5_IOS
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @param appName 应用名
* @param bundleId bundle_id
* @return IOS移动应用场景
*/
public static String H5_IOS(String appName, String bundleId) {
JSONObject _returnValue = new JSONObject();
//
JSONObject _params = new JSONObject();
_params.put("type", "IOS");
_params.put("app_name", appName);
_params.put("bundle_id", bundleId);
_returnValue.put("h5_info", _params);
//
return _returnValue.toJSONString();
}
示例8: begin
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static String begin() {
JSONObject jsonObject = template();
StringBuilder builder = new StringBuilder("* ").append("开启12306抢票任务").append("\n");
builder.append("* [开始抢票](").append(HostConfig.domain).append("/task/begin").append(")\n");
jsonObject.put("text", builder.toString());
return jsonObject.toJSONString();
}
示例9: buildRequestParams
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
protected AsyncRequest buildRequestParams() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("vfwebqq", session.getVfwebqq());
jsonObject.put("hash", WqqEncryptor.hash(String.valueOf(session.getUin()), session.getPtwebqq()));
Parameters params = new Parameters("r", jsonObject.toJSONString());
Headers headers = new Headers("Referer", RequestUrls.referer_common.url);
return new AsyncRequest(RequestUrls.get_user_friends2.url, HttpMethod.post, params, headers);
}
示例10: getUserById
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 返回text格式数据
* @param id 主键id
* @return 用户json字符串
*/
@RequestMapping("/get/id/{id}")
@ResponseBody
public String getUserById(@PathVariable("id")String id){
logger.info("request /user/get/id/{id}, parameter is "+id);
User user = userService.getById(Integer.parseInt(id));
return JSONObject.toJSONString(user);
}
示例11: success
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
protected String success(Object obj) {
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("code", "0");
resultMap.put("msg", "成功");
resultMap.put("result", obj);
return JSONObject.toJSONString(resultMap);
}
示例12: queryPayOrder
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@RequestMapping(value = "/pay/query")
public String queryPayOrder(@RequestParam String jsonParam) {
_log.info("selectPayOrder << {}", jsonParam);
JSONObject retObj = new JSONObject();
retObj.put("code", "0000");
if(StringUtils.isBlank(jsonParam)) {
retObj.put("code", "0001"); // 参数错误
retObj.put("msg", "缺少参数");
return retObj.toJSONString();
}
JSONObject paramObj = JSON.parseObject(new String(MyBase64.decode(jsonParam)));
String mchId = paramObj.getString("mchId");
String payOrderId = paramObj.getString("payOrderId");
String mchOrderNo = paramObj.getString("mchOrderNo");
PayOrder payOrder;
if(StringUtils.isNotBlank(payOrderId)) {
payOrder = payOrderService.selectPayOrderByMchIdAndPayOrderId(mchId, payOrderId);
}else {
payOrder = payOrderService.selectPayOrderByMchIdAndMchOrderNo(mchId, mchOrderNo);
}
if(payOrder == null) {
retObj.put("code", "0002");
retObj.put("msg", "支付订单不存在");
return retObj.toJSONString();
}
//
boolean executeNotify = paramObj.getBooleanValue("executeNotify");
// 如果选择回调且支付状态为支付成功,则回调业务系统
if(executeNotify && payOrder.getStatus() == PayConstant.PAY_STATUS_SUCCESS) {
this.doNotify(payOrder);
}
retObj.put("result", JSON.toJSON(payOrder));
_log.info("selectPayOrder >> {}", retObj);
return retObj.toJSONString();
}
示例13: progressNotic
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 报修处理进展通知
*/
public static boolean progressNotic() {
boolean isOk = false;
String token = WeiXinUtils.getToken();
if (token != null) {
String urlString = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
try {
// op-51t-YG9RE_Pcfr9WD8e9MRYN0
WXMessasgeTemplate wxMessasgeTemplate = new WXMessasgeTemplate();
// wxMessasgeTemplate.setTouser("op-51t5m2L_VLsDvXXDdSm-BOToY");
wxMessasgeTemplate.setTouser("op-51t-YG9RE_Pcfr9WD8e9MRYN0");
wxMessasgeTemplate.setTemplate_id("7GabJuZ-w-0ZTKMdajfmXB3WBVCp55NAmnrUS_IqU3Y");
wxMessasgeTemplate.setUrl("http://weixin.qq.com/download");
JSONObject jsonObject = new JSONObject();
JSONObject firstJsonObject = new JSONObject();
firstJsonObject.put("value", "尊敬的耿adfasf:您的报修有新的进展。");
jsonObject.put("first", firstJsonObject);
JSONObject key1 = new JSONObject();
key1.put("value", "郑汴路dfasfdf");
jsonObject.put("keyword1", key1);
JSONObject key2 = new JSONObject();
key2.put("value", "郑汴路adfasf1");
jsonObject.put("keyword2", key2);
JSONObject key3 = new JSONObject();
key3.put("value", "郑汴路2adfasf");
jsonObject.put("keyword3", key3);
JSONObject key4 = new JSONObject();
key4.put("value", "郑汴路asdfasf3");
jsonObject.put("keyword4", key4);
JSONObject key5 = new JSONObject();
key5.put("value", "郑汴路afdasf4");
jsonObject.put("keyword5", key5);
JSONObject remark = new JSONObject();
remark.put("value", "3ks!");
jsonObject.put("remark", remark);
wxMessasgeTemplate.setData(jsonObject);
URL url = new URL(urlString);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
String kfAccountString = JSONObject.toJSONString(wxMessasgeTemplate);
httpsURLConnection.setRequestProperty("Content-length", String.valueOf(kfAccountString.length()));
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setDoInput(true);
DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream());
dataOutputStream.write(kfAccountString.getBytes());
dataOutputStream.flush();
dataOutputStream.close();
DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
StringBuffer stringBuffer = new StringBuffer();
int inputByte = dataInputStream.read();
while (inputByte != -1) {
stringBuffer.append((char) inputByte);
inputByte = dataInputStream.read();
}
String kfString = stringBuffer.toString();
System.out.println(kfString);
JSONObject jsonObject1 = JSON.parseObject(kfString);
if (jsonObject1.containsKey("errcode")) {
int errcode = jsonObject1.getIntValue("errcode");
if (errcode == 0) {
isOk = true;
} else {
//TODO 添加客服账号失败
isOk = false;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return isOk;
}
示例14: buildMessProto
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static String buildMessProto(int uid,String nick, String mess) {
ChatProto chatProto = new ChatProto(MESS_PROTO, mess);
chatProto.extend.put("uid", uid);
chatProto.extend.put("nick", nick);
chatProto.extend.put("time", DateTimeUtil.getCurrentTime());
return JSONObject.toJSONString(chatProto);
}
示例15: sendMessage
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 发送消息
* @param appid
* @param appsecret
* @param message 具体消息实体
* @return
*/
public static boolean sendMessage(String appid, String appsecret, Object message, String accessToken){
/**
* 消息发送状态 true:成功 false:失败
*/
boolean flag = false;
//Token accessToken = CommonUtil.getAccessToken(appid, appsecret);
if(null != accessToken){
logger.info("发送用户消息工具类textMessage获取到的token:{}",accessToken);
requestUrl = requestUrl.replace("AT", accessToken);
/**
* 将消息转换为json数据
*/
String jsonMessage = JSONObject.toJSONString(message);
/**
* 发送消息
*/
CommonUtil.httpsRequest(requestUrl, "POST", jsonMessage);
flag = true;
}
return flag;
}