當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.toJSONString方法代碼示例

本文整理匯總了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();
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:36,代碼來源:CustomerMsg.java

示例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();
}
 
開發者ID:suninformation,項目名稱:ymate-payment-v2,代碼行數:15,代碼來源:WxPayJsApiController.java

示例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;
}
 
開發者ID:gongjunhao,項目名稱:car-bjpermit,代碼行數:37,代碼來源:HttpClientUtils.java

示例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+"";
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:54,代碼來源:GoodsOrderController.java

示例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);
}
 
開發者ID:thankjava,項目名稱:smartqq-agreement-core,代碼行數:10,代碼來源:GetGroupNameListMask2.java

示例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 "";
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:48,代碼來源:WeiXinCompanySendMsg.java

示例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();
}
 
開發者ID:suninformation,項目名稱:ymate-payment-v2,代碼行數:17,代碼來源:WxPaySceneInfo.java

示例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();
}
 
開發者ID:justice-code,項目名稱:Thrush,代碼行數:8,代碼來源:MarkDownUtil.java

示例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);
}
 
開發者ID:thankjava,項目名稱:smartqq-agreement-core,代碼行數:10,代碼來源:GetUserFriends2.java

示例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);
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:13,代碼來源:UserController.java

示例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);
}
 
開發者ID:wenjian-li,項目名稱:spring_mybatis_shiro,代碼行數:8,代碼來源:BaseController.java

示例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();
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:37,代碼來源:PayOrderServiceController.java

示例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;
    }
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:81,代碼來源:WeiXinWYUtils.java

示例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);
}
 
開發者ID:beyondfengyu,項目名稱:HappyChat,代碼行數:8,代碼來源:ChatProto.java

示例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;
}
 
開發者ID:tojaoomy,項目名稱:private-WeChat,代碼行數:34,代碼來源:SendMessageUtil.java


注:本文中的com.alibaba.fastjson.JSONObject.toJSONString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。