

优质服务商家
5*8小时在线客服
专业测试保证品质
API文档
新闻查询接口
调用地址:https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news
请求方式:GET
返回类型:JSON
请求参数(Headers)
名称
|
类型
|
是否必须
|
描述
|
---|---|---|---|
暂无数据
|
请求参数(Query)
名称
|
类型
|
是否必须
|
描述
|
---|---|---|---|
channelId
|
string
|
否
|
新闻频道id,必须精确匹配
|
channelName
|
string
|
否
|
新闻频道名称,可模糊匹配
|
needAllList
|
string
|
否
|
是否需要最全的返回资料。包括每一段文本和每一张图。用list的形式返回。
|
needContent
|
string
|
否
|
是否需要返回正文,1为需要,其他为不需要
|
page
|
string
|
否
|
页数,默认1。每页最多20条记录。
|
title
|
string
|
否
|
标题名称,可模糊匹配
|
请求参数(Body)
名称
|
类型
|
是否必须
|
描述
|
---|---|---|---|
暂无数据
|
请求示例
curl -v -X GET https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news ?channelId=&channelName=&needAllList=&needContent=&page=1&title=-H 'Host:service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest'
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
package main
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
gourl "net/url"
"strings"
"time"
)
func calcAuthorization(source string, secretId string, secretKey string) (auth string, datetime string, err error) {
timeLocation, _ := time.LoadLocation("Etc/GMT")
datetime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
signStr := fmt.Sprintf("x-date: %s\nx-source: %s", datetime, source)
// hmac-sha1
mac := hmac.New(sha1.New, []byte(secretKey))
mac.Write([]byte(signStr))
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
auth = fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"%s\"",
secretId, sign)
return auth, datetime, nil
}
func urlencode(params map[string]string) string {
var p = gourl.Values{}
for k, v := range params {
p.Add(k, v)
}
return p.Encode()
}
func main() {
// 云市场分配的密钥Id
secretId := "xxxx"
// 云市场分配的密钥Key
secretKey := "xxxx"
source := "market"
// 签名
auth, datetime, _ := calcAuthorization(source, secretId, secretKey)
// 请求方法
method := "GET"
// 请求头
headers := map[string]string{"X-Source": source, "X-Date": datetime, "Authorization": auth}
// 查询参数
queryParams := make(map[string]string)
queryParams["channelId"] = ""
queryParams["channelName"] = ""
queryParams["needAllList"] = ""
queryParams["needContent"] = ""
queryParams["page"] = "1"
queryParams["title"] = ""
// body参数
bodyParams := make(map[string]string)
// url参数拼接
url := "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news"
if len(queryParams) > 0 {
url = fmt.Sprintf("%s?%s", url, urlencode(queryParams))
}
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
var body io.Reader = nil
if bodyMethods[method] {
body = strings.NewReader(urlencode(bodyParams))
headers["Content-Type"] = "application/x-www-form-urlencoded"
}
client := &http.Client{
Timeout: 5 * time.Second,
}
request, err := http.NewRequest(method, url, body)
if err != nil {
panic(err)
}
for k, v := range headers {
request.Header.Set(k, v)
}
response, err := client.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
panic(err)
}
fmt.Println(string(bodyBytes))
}
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
class Demo {
public static String calcAuthorization(String source, String secretId, String secretKey, String datetime)
throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
String signStr = "x-date: " + datetime + "\n" + "x-source: " + source;
Mac mac = Mac.getInstance("HmacSHA1");
Key sKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm());
mac.init(sKey);
byte[] hash = mac.doFinal(signStr.getBytes("UTF-8"));
String sig = new BASE64Encoder().encode(hash);
String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"" + sig + "\"";
return auth;
}
public static String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
StringBuilder sb = new StringBuilder();
for (Map.Entry<?, ?> entry : map.entrySet()) {
if (sb.length() > 0) {
sb.append("&");
}
sb.append(String.format("%s=%s",
URLEncoder.encode(entry.getKey().toString(), "UTF-8"),
URLEncoder.encode(entry.getValue().toString(), "UTF-8")
));
}
return sb.toString();
}
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
//云市场分配的密钥Id
String secretId = "xxxx";
//云市场分配的密钥Key
String secretKey = "xxxx";
String source = "market";
Calendar cd = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String datetime = sdf.format(cd.getTime());
// 签名
String auth = calcAuthorization(source, secretId, secretKey, datetime);
// 请求方法
String method = "GET";
// 请求头
Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Source", source);
headers.put("X-Date", datetime);
headers.put("Authorization", auth);
// 查询参数
Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put("channelId","");
queryParams.put("channelName","");
queryParams.put("needAllList","");
queryParams.put("needContent","");
queryParams.put("page","1");
queryParams.put("title","");
// body参数
Map<String, String> bodyParams = new HashMap<String, String>();
// url参数拼接
String url = "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news";
if (!queryParams.isEmpty()) {
url += "?" + urlencode(queryParams);
}
BufferedReader in = null;
try {
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestMethod(method);
// request headers
for (Map.Entry<String, String> entry : headers.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
// request body
Map<String, Boolean> methods = new HashMap<>();
methods.put("POST", true);
methods.put("PUT", true);
methods.put("PATCH", true);
Boolean hasBody = methods.get(method);
if (hasBody != null) {
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.writeBytes(urlencode(bodyParams));
out.flush();
out.close();
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String result = "";
while ((line = in.readLine()) != null) {
result += line;
}
System.out.println(result);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
/**
* npm install crypto-js request
*/
var CryptoJS = require("crypto-js");
var request = require('request');
var querystring = require('querystring');
// 云市场分配的密钥Id
var secretId = "xxx";
// 云市场分配的密钥Key
var secretKey = "xxx";
var source = "market";
// 签名
var datetime = (new Date()).toGMTString();
var signStr = "x-date: " + datetime + "\n" + "x-source: " + source;
var sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(signStr, secretKey))
var auth = 'hmac id="' + secretId + '", algorithm="hmac-sha1", headers="x-date x-source", signature="' + sign + '"';
// 请求方法
var method = "GET";
// 请求头
var headers = {
"X-Source": source,
"X-Date": datetime,
"Authorization": auth,
}
// 查询参数
var queryParams = {
"channelId": "",
"channelName": "",
"needAllList": "",
"needContent": "",
"page": "1",
"title": ""}
// body参数(POST方法下)
var bodyParams = {
}
// url参数拼接
var url = "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news";
if (Object.keys(queryParams).length > 0) {
url += '?' + querystring.stringify(queryParams);
}
var options = {
url: url,
timeout: 5000,
method: method,
headers: headers
}
if (['POST', 'PUT', 'PATCH'].indexOf(method) != -1) {
options['body'] = querystring.stringify(bodyParams);
options['headers']['Content-Type'] = "application/x-www-form-urlencoded";
}
request(options, function (error, response, body) {
if (error !== null) {
console.log('error:', error);
return;
}
console.log(body);
});
<?php
// 云市场分配的密钥Id
$secretId = 'xxxx';
// 云市场分配的密钥Key
$secretKey = 'xxxx';
$source = 'market';
// 签名
$datetime = gmdate('D, d M Y H:i:s T');
$signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
$sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
$auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
// 请求方法
$method = 'GET';
// 请求头
$headers = array(
'X-Source' => $source,
'X-Date' => $datetime,
'Authorization' => $auth,
);
// 查询参数
$queryParams = array (
'channelId' => '',
'channelName' => '',
'needAllList' => '',
'needContent' => '',
'page' => '1',
'title' => '',
);
// body参数(POST方法下)
$bodyParams = array (
);
// url参数拼接
$url = 'https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news';
if (count($queryParams) > 0) {
$url .= '?' . http_build_query($queryParams);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($v, $k) {
return $k . ': ' . $v;
}, array_values($headers), array_keys($headers)));
if (in_array($method, array('POST', 'PUT', 'PATCH'), true)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($bodyParams));
}
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
print_r($data);
}
curl_close($ch);
# -*- coding: utf-8 -*-
from __future__ import print_function
import ssl, hmac, base64, hashlib
from datetime import datetime as pydatetime
try:
from urllib import urlencode
from urllib2 import Request, urlopen
except ImportError:
from urllib.parse import urlencode
from urllib.request import Request, urlopen
# 云市场分配的密钥Id
secretId = "xxxx"
# 云市场分配的密钥Key
secretKey = "xxxx"
source = "market"
# 签名
datetime = pydatetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
signStr = "x-date: %s\nx-source: %s" % (datetime, source)
sign = base64.b64encode(hmac.new(secretKey.encode('utf-8'), signStr.encode('utf-8'), hashlib.sha1).digest())
auth = 'hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"' % (secretId, sign.decode('utf-8'))
# 请求方法
method = 'GET'
# 请求头
headers = {
'X-Source': source,
'X-Date': datetime,
'Authorization': auth,
}
# 查询参数
queryParams = {
"channelId": "",
"channelName": "",
"needAllList": "",
"needContent": "",
"page": "1",
"title": ""}
# body参数(POST方法下存在)
bodyParams = {
}
# url参数拼接
url = 'https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news'
if len(queryParams.keys()) > 0:
url = url + '?' + urlencode(queryParams)
request = Request(url, headers=headers)
request.get_method = lambda: method
if method in ('POST', 'PUT', 'PATCH'):
request.data = urlencode(bodyParams).encode('utf-8')
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urlopen(request, context=ctx)
content = response.read()
if content:
print(content.decode('utf-8'))
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;
public class CsharpTest
{
public static String HMACSHA1Text(String EncryptText, String EncryptKey)
{
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);
byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
return Convert.ToBase64String(hashBytes);
}
public static void Main(String[] args)
{
String url = "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/news";
String method = "GET";
String querys = "channelId=&channelName=&needAllList=&needContent=&page=1&title=";
String source = "market";
//云市场分配的密钥Id
String secretId = "xxx";
//云市场分配的密钥Key
String secretKey = "xxx";
String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0];
url = url + "?" + querys;
String signStr = "x-date: " + dt + "\n" + "x-source: " + source;
String sign = HMACSHA1Text(signStr, secretKey);
String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"";
auth = auth + sign + "\"";
Console.WriteLine(auth + "\n");
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (url.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", auth);
httpRequest.Headers.Add("X-Source", source);
httpRequest.Headers.Add("X-Date", dt);
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
}
正常返回示例
{
"showapi_res_code": 0,
"showapi_res_error": "",
"showapi_res_body": {
"ret_code": 0,
"pagebean": {
"allPages": 5,
"contentlist": [
{
"allList": [
"足球,有着“世界第一运动”的美誉,是全球体育界最具影响力的单项体育运动。就在几天前,一场足球盛宴——欧洲杯完美落幕,回首历时近一个月的赛程,足球所带来的热血与激情,伴随着球迷朋友们一起见证了一个个不眠之夜,其魅力自然可见一斑。",
"而在漳州,也有一批热爱足球运动的青少年,这些小足球员们“小荷才露尖尖角”,他们挥洒汗水,正义无反顾地向着“足球梦”追逐奔跑。",
"张梦丽与其他踢球的孩子一样,为了足球她也笑过、也哭过。学校里女子足球队成立的时候,是她最开心的时候,因为球队的创立代表着自己有展示自我风采的舞台,可以出去比赛了。后来因为年龄大了几个月,她没有办法进入省队,也没能去参加省里的比赛,这些都成了她的遗憾。",
"一路走来,足球成了张梦丽最喜欢的东西。有时,她会梦到自己到省队了,或者去参加比赛了,这时她甚至会激动得醒来。学习成绩在班级排名中上的她表示,未来自己想考到好的学校,但同时不会放弃对足球的执着与热爱。"
],
"pubDate": "2016-07-14 11:36:05",
"title": "漳州足球大数据:拥有足球特色学校91所国家级46所",
"channelName": "社会最新",
"imageurls": [],
"desc": "就在几天前,一场足球盛宴——欧洲杯完美落幕,回首历时近一个月的赛程,足球所带来的热血与激情,伴随着球迷朋友们一起见证了一个个不眠之夜,其魅力自然可见一斑。在漳州,也有一批热爱足球运动的青少年,这些小足球员们“小荷才露尖尖角”,他们挥洒汗水,正义无反顾地向着“足球梦”追逐奔跑。",
"source": "手机中国",
"channelId": "5572a10bb3cdc86cf39001f8",
"nid": "10427894029754912460",
"link": "http://m.china.com.cn/baidu/doc_1_3_1596740.html"
},
{
"allList": [
"提起万达,很多人也许会自然联想到另一个词——并购,这仿佛已经成了王老板的主要生存法则。两天前,万达集团旗下的美国AMC院线宣布,以9.21亿英镑的价格并购欧洲第一大院线——Odeon & UCI院线,在“买买买”的路上又迈出震惊世界的一步。",
"体育和影视可以说是万达文化产业的左膀右臂,万达影视的并购之路方兴未艾,而万达体育自成立之后更是大动作不断。以盈方体育传媒集团和世界铁人公司为基底的万达体育,到了2016年开始将重心转向经营,先是成为国际足联顶级赞助商,随后又成为国际篮联全球独家商业合作伙伴。插上这对翅膀的万达体育除了继续扩充自己的资源池以外,还开始向世界展示自己的品牌影响力。",
],
"pubDate": "2016-07-14 10:48:04",
"title": "创立“中国杯” 习惯了“买买买”的万达要靠自创IP为中国足球出把力",
"channelName": "国内最新",
"imageurls": [],
"desc": "“中国杯”则是万达与国际足联合作的第一项赛事落地,这也标志着万达开始着重加强自己的赛事运营业务。"
"source": "禹唐体育",
"sentiment_display": 0,
"channelId": "5572a109b3cdc86cf39001db",
"nid": "2623216982465905421",
"link": "http://ytsports.cn/news-10662.html?cid=64"
},
{
"allList": [
{
"height": 426,
"width": 640,
"url": "http://img1.gtimg.com/sports/pics/hv1/198/144/2098/136459368.jpg"
},
"《体育产业发展“十三五”规划》指出,积极研究推进发行以中国足球职业联赛为竞猜对象的",
"腾讯体育7月14日讯 13日,国家体育总局在其官网刊登了《体育产业发展“十三五”规划》,其中明确指出,加强三大球联赛建设、积极研究推进积极研究推进发行以中国足球职业联赛为竞猜对象的足球"
],
"pubDate": "2016-07-14 10:17:26",
"title": "体育产业"十三五"规划:推进中国足球联赛竞彩",
"channelName": "国内足球最新",
"imageurls": [
{
"height": 426,
"width": 640,
"url": "http://img1.gtimg.com/sports/pics/hv1/198/144/2098/136459368.jpg"
}
],
"desc": "《体育产业发展“十三五”规划》指出,积极研究推进发行以中国足球职业联赛为竞猜对象的足球彩票腾讯体育7月14日讯13日,国家体育总局在其官网刊登了《体育产业发展“十三五”规划》,其中明确指出,加强三大球联赛建设、积极研究推进积极研究推进发行以中国足球职业联赛为竞猜对象的足球彩票。《体育产业发展“十三五”规",
"source": "国内足球新闻",
"channelId": "5572a10ab3cdc86cf39001e8",
"link": "http://sports.qq.com/a/20160714/021723.htm"
}
],
"currentPage": 1,
"allNum": 94,
"maxResult": 20
}
}
}
失败返回示例
{
"showapi_res_code": -1,
"showapi_res_error": "失败信息",
"showapi_res_body": {}
}
返回码定义
返回码
|
返回信息
|
描述
|
---|---|---|
无参数
|
新闻频道查询
调用地址:https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel
请求方式:GET
返回类型:JSON
请求参数(Headers)
名称
|
类型
|
是否必须
|
描述
|
---|---|---|---|
暂无数据
|
请求参数(Query)
名称
|
类型
|
是否必须
|
描述
|
---|---|---|---|
暂无数据
|
请求参数(Body)
名称
|
类型
|
是否必须
|
描述
|
---|---|---|---|
暂无数据
|
请求示例
curl -v -X GET https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel -H 'Host:service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest'
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
package main
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
gourl "net/url"
"strings"
"time"
)
func calcAuthorization(source string, secretId string, secretKey string) (auth string, datetime string, err error) {
timeLocation, _ := time.LoadLocation("Etc/GMT")
datetime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
signStr := fmt.Sprintf("x-date: %s\nx-source: %s", datetime, source)
// hmac-sha1
mac := hmac.New(sha1.New, []byte(secretKey))
mac.Write([]byte(signStr))
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
auth = fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"%s\"",
secretId, sign)
return auth, datetime, nil
}
func urlencode(params map[string]string) string {
var p = gourl.Values{}
for k, v := range params {
p.Add(k, v)
}
return p.Encode()
}
func main() {
// 云市场分配的密钥Id
secretId := "xxxx"
// 云市场分配的密钥Key
secretKey := "xxxx"
source := "market"
// 签名
auth, datetime, _ := calcAuthorization(source, secretId, secretKey)
// 请求方法
method := "GET"
// 请求头
headers := map[string]string{"X-Source": source, "X-Date": datetime, "Authorization": auth}
// 查询参数
queryParams := make(map[string]string)
// body参数
bodyParams := make(map[string]string)
// url参数拼接
url := "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel"
if len(queryParams) > 0 {
url = fmt.Sprintf("%s?%s", url, urlencode(queryParams))
}
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
var body io.Reader = nil
if bodyMethods[method] {
body = strings.NewReader(urlencode(bodyParams))
headers["Content-Type"] = "application/x-www-form-urlencoded"
}
client := &http.Client{
Timeout: 5 * time.Second,
}
request, err := http.NewRequest(method, url, body)
if err != nil {
panic(err)
}
for k, v := range headers {
request.Header.Set(k, v)
}
response, err := client.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
panic(err)
}
fmt.Println(string(bodyBytes))
}
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
class Demo {
public static String calcAuthorization(String source, String secretId, String secretKey, String datetime)
throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
String signStr = "x-date: " + datetime + "\n" + "x-source: " + source;
Mac mac = Mac.getInstance("HmacSHA1");
Key sKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), mac.getAlgorithm());
mac.init(sKey);
byte[] hash = mac.doFinal(signStr.getBytes("UTF-8"));
String sig = new BASE64Encoder().encode(hash);
String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"" + sig + "\"";
return auth;
}
public static String urlencode(Map<?, ?> map) throws UnsupportedEncodingException {
StringBuilder sb = new StringBuilder();
for (Map.Entry<?, ?> entry : map.entrySet()) {
if (sb.length() > 0) {
sb.append("&");
}
sb.append(String.format("%s=%s",
URLEncoder.encode(entry.getKey().toString(), "UTF-8"),
URLEncoder.encode(entry.getValue().toString(), "UTF-8")
));
}
return sb.toString();
}
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
//云市场分配的密钥Id
String secretId = "xxxx";
//云市场分配的密钥Key
String secretKey = "xxxx";
String source = "market";
Calendar cd = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String datetime = sdf.format(cd.getTime());
// 签名
String auth = calcAuthorization(source, secretId, secretKey, datetime);
// 请求方法
String method = "GET";
// 请求头
Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Source", source);
headers.put("X-Date", datetime);
headers.put("Authorization", auth);
// 查询参数
Map<String, String> queryParams = new HashMap<String, String>();
// body参数
Map<String, String> bodyParams = new HashMap<String, String>();
// url参数拼接
String url = "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel";
if (!queryParams.isEmpty()) {
url += "?" + urlencode(queryParams);
}
BufferedReader in = null;
try {
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestMethod(method);
// request headers
for (Map.Entry<String, String> entry : headers.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
// request body
Map<String, Boolean> methods = new HashMap<>();
methods.put("POST", true);
methods.put("PUT", true);
methods.put("PATCH", true);
Boolean hasBody = methods.get(method);
if (hasBody != null) {
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoOutput(true);
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.writeBytes(urlencode(bodyParams));
out.flush();
out.close();
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String result = "";
while ((line = in.readLine()) != null) {
result += line;
}
System.out.println(result);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
/**
* npm install crypto-js request
*/
var CryptoJS = require("crypto-js");
var request = require('request');
var querystring = require('querystring');
// 云市场分配的密钥Id
var secretId = "xxx";
// 云市场分配的密钥Key
var secretKey = "xxx";
var source = "market";
// 签名
var datetime = (new Date()).toGMTString();
var signStr = "x-date: " + datetime + "\n" + "x-source: " + source;
var sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(signStr, secretKey))
var auth = 'hmac id="' + secretId + '", algorithm="hmac-sha1", headers="x-date x-source", signature="' + sign + '"';
// 请求方法
var method = "GET";
// 请求头
var headers = {
"X-Source": source,
"X-Date": datetime,
"Authorization": auth,
}
// 查询参数
var queryParams = {
}
// body参数(POST方法下)
var bodyParams = {
}
// url参数拼接
var url = "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel";
if (Object.keys(queryParams).length > 0) {
url += '?' + querystring.stringify(queryParams);
}
var options = {
url: url,
timeout: 5000,
method: method,
headers: headers
}
if (['POST', 'PUT', 'PATCH'].indexOf(method) != -1) {
options['body'] = querystring.stringify(bodyParams);
options['headers']['Content-Type'] = "application/x-www-form-urlencoded";
}
request(options, function (error, response, body) {
if (error !== null) {
console.log('error:', error);
return;
}
console.log(body);
});
<?php
// 云市场分配的密钥Id
$secretId = 'xxxx';
// 云市场分配的密钥Key
$secretKey = 'xxxx';
$source = 'market';
// 签名
$datetime = gmdate('D, d M Y H:i:s T');
$signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
$sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
$auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
// 请求方法
$method = 'GET';
// 请求头
$headers = array(
'X-Source' => $source,
'X-Date' => $datetime,
'Authorization' => $auth,
);
// 查询参数
$queryParams = array (
);
// body参数(POST方法下)
$bodyParams = array (
);
// url参数拼接
$url = 'https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel';
if (count($queryParams) > 0) {
$url .= '?' . http_build_query($queryParams);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($v, $k) {
return $k . ': ' . $v;
}, array_values($headers), array_keys($headers)));
if (in_array($method, array('POST', 'PUT', 'PATCH'), true)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($bodyParams));
}
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
print_r($data);
}
curl_close($ch);
# -*- coding: utf-8 -*-
from __future__ import print_function
import ssl, hmac, base64, hashlib
from datetime import datetime as pydatetime
try:
from urllib import urlencode
from urllib2 import Request, urlopen
except ImportError:
from urllib.parse import urlencode
from urllib.request import Request, urlopen
# 云市场分配的密钥Id
secretId = "xxxx"
# 云市场分配的密钥Key
secretKey = "xxxx"
source = "market"
# 签名
datetime = pydatetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
signStr = "x-date: %s\nx-source: %s" % (datetime, source)
sign = base64.b64encode(hmac.new(secretKey.encode('utf-8'), signStr.encode('utf-8'), hashlib.sha1).digest())
auth = 'hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"' % (secretId, sign.decode('utf-8'))
# 请求方法
method = 'GET'
# 请求头
headers = {
'X-Source': source,
'X-Date': datetime,
'Authorization': auth,
}
# 查询参数
queryParams = {
}
# body参数(POST方法下存在)
bodyParams = {
}
# url参数拼接
url = 'https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel'
if len(queryParams.keys()) > 0:
url = url + '?' + urlencode(queryParams)
request = Request(url, headers=headers)
request.get_method = lambda: method
if method in ('POST', 'PUT', 'PATCH'):
request.data = urlencode(bodyParams).encode('utf-8')
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urlopen(request, context=ctx)
content = response.read()
if content:
print(content.decode('utf-8'))
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;
public class CsharpTest
{
public static String HMACSHA1Text(String EncryptText, String EncryptKey)
{
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);
byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
return Convert.ToBase64String(hashBytes);
}
public static void Main(String[] args)
{
String url = "https://service-o5ikp40z-1255468759.ap-shanghai.apigateway.myqcloud.com/release/channel";
String method = "GET";
String querys = "";
String source = "market";
//云市场分配的密钥Id
String secretId = "xxx";
//云市场分配的密钥Key
String secretKey = "xxx";
String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0];
url = url + "?" + querys;
String signStr = "x-date: " + dt + "\n" + "x-source: " + source;
String sign = HMACSHA1Text(signStr, secretKey);
String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"";
auth = auth + sign + "\"";
Console.WriteLine(auth + "\n");
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (url.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", auth);
httpRequest.Headers.Add("X-Source", source);
httpRequest.Headers.Add("X-Date", dt);
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
}
正常返回示例
{
"showapi_res_code": 0,
"showapi_res_error": "",
"showapi_res_body": {
"totalNum": 44,
"ret_code": 0,
"channelList": [
{
"channelId": "5572a108b3cdc86cf39001cd",
"name": "国内焦点"
},
{
"channelId": "5572a108b3cdc86cf39001ce",
"name": "国际焦点"
},
{
"channelId": "5572a108b3cdc86cf39001cf",
"name": "军事焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d0",
"name": "财经焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d1",
"name": "互联网焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d2",
"name": "房产焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d3",
"name": "汽车焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d4",
"name": "体育焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d5",
"name": "娱乐焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d6",
"name": "游戏焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d7",
"name": "教育焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d8",
"name": "女人焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d9",
"name": "科技焦点"
},
{
"channelId": "5572a109b3cdc86cf39001da",
"name": "社会焦点"
},
{
"channelId": "5572a109b3cdc86cf39001db",
"name": "国内最新"
},
{
"channelId": "5572a109b3cdc86cf39001dc",
"name": "台湾最新"
},
{
"channelId": "5572a109b3cdc86cf39001dd",
"name": "港澳最新"
},
{
"channelId": "5572a109b3cdc86cf39001de",
"name": "国际最新"
},
{
"channelId": "5572a109b3cdc86cf39001df",
"name": "军事最新"
},
{
"channelId": "5572a109b3cdc86cf39001e0",
"name": "财经最新"
},
{
"channelId": "5572a109b3cdc86cf39001e1",
"name": "理财最新"
},
{
"channelId": "5572a109b3cdc86cf39001e2",
"name": "宏观经济最新"
},
{
"channelId": "5572a109b3cdc86cf39001e3",
"name": "互联网最新"
},
{
"channelId": "5572a109b3cdc86cf39001e4",
"name": "房产最新"
},
{
"channelId": "5572a109b3cdc86cf39001e5",
"name": "汽车最新"
},
{
"channelId": "5572a109b3cdc86cf39001e6",
"name": "体育最新"
},
{
"channelId": "5572a10ab3cdc86cf39001e7",
"name": "国际足球最新"
},
{
"channelId": "5572a10ab3cdc86cf39001e8",
"name": "国内足球最新"
},
{
"channelId": "5572a10ab3cdc86cf39001e9",
"name": "CBA最新"
},
{
"channelId": "5572a10ab3cdc86cf39001ea",
"name": "综合体育最新"
},
{
"channelId": "5572a10ab3cdc86cf39001eb",
"name": "娱乐最新"
},
{
"channelId": "5572a10ab3cdc86cf39001ec",
"name": "电影最新"
},
{
"channelId": "5572a10ab3cdc86cf39001ed",
"name": "电视最新"
},
{
"channelId": "5572a10ab3cdc86cf39001ee",
"name": "游戏最新"
},
{
"channelId": "5572a10ab3cdc86cf39001ef",
"name": "教育最新"
},
{
"channelId": "5572a10ab3cdc86cf39001f0",
"name": "女人最新"
},
{
"channelId": "5572a10ab3cdc86cf39001f1",
"name": "美容护肤最新"
},
{
"channelId": "5572a10ab3cdc86cf39001f2",
"name": "情感两性最新"
},
{
"channelId": "5572a10ab3cdc86cf39001f3",
"name": "健康养生最新"
},
{
"channelId": "5572a10ab3cdc86cf39001f4",
"name": "科技最新"
},
{
"channelId": "5572a10bb3cdc86cf39001f5",
"name": "数码最新"
},
{
"channelId": "5572a10bb3cdc86cf39001f6",
"name": "电脑最新"
},
{
"channelId": "5572a10bb3cdc86cf39001f7",
"name": "科普最新"
},
{
"channelId": "5572a10bb3cdc86cf39001f8",
"name": "社会最新"
}
]
}
}
失败返回示例
{
"showapi_res_code": -1,
"showapi_res_error": "失败信息",
"showapi_res_body": {}
}
返回码定义
返回码
|
返回信息
|
描述
|
---|---|---|
无参数
|
商品介绍
使用指南
1购买完成后,点击进入控制台

2在控制台点击”管理“查看详情”

3获得API的SecretID和SecretKey后,即可按照商品介绍里的方式调用API

累计评价(0)
综合评分
-