授权API文档

鹏程万里视频加密系统授权API是为了方便视频经销商,完成无人值守视频销售系统,自动化用户播放授权而打造的,通过授权API可以与网站、微信公众号、微信小程序等应用进行对接,实现无人值守的自动化视频销售系统。注意:只有鹏程万里视频加密系统的网络授权版才可以使用授权API的功能,网络授权版的子账户无法使用授权API。如果您使用了锁定账户的功能或您的账户出现了违规被封的情况,授权API将无法完成请求。

登录鹏程万里视频加密系统后进入主界面,点击最下方的【API】文本,系统会提供给您 APPID 和 APPKEY 的参数值,其中APPID是您接入授权API的唯一验证ID,APPKEY是作为授权API参数验证的重要参数,需要妥善保存,不可外泄。目前 APPID 和 APPKEY 两个参数一旦生成,便不可修改,请确保不要外泄。使用授权API添加视频播放用户授权时,每添加一个播放用户授权会自动扣除一个授权点数,请保证您的授权点数充足,如果您的授权点数为0,授权API将无法完成请求。

接口地址:https://www.pcwlenv.com/api/GetAllVideoInfo.php
接口说明:获取当前商户的所有加密视频信息。
返回格式:json
请求方式:https post

请求参数说明:

参数 必填 类型 说明 示例值
  appid string 鹏程万里视频加密系统分配给您接入授权API的应用ID PCWL5874647331
  method string 需要调用授权API的名称 GetAllVideoInfo
  timestamp int 发送请求的Unix时间戳,精确到秒,北京时间误差不超30秒 1555127238
  version string 授权API的版本,该参数值目前固定为1.0 1.0
  sign string 商户请求参数的签名串,请将所有的请求参数(sign除外)按照顺序组合成一个串,最后组合上您的APPKEY进行sha1加密求值,并赋值给sign参数 81e9209e64bdd3a52fa01ece075eaa947db8fc49

返回参数说明:

参数 类型 说明 示例值
  code string 授权api请求返回码 2000
  msg string 授权api请求返回码描述 服务器错误
  VideoCode int 请求返回的视频编号 5161653338483
  VideoName string 请求返回的视频名称 视频名称测试
  VideoExplain string 请求返回的视频说明 视频说明测试

返回代码说明:

返回码 说明
  1000 操作完成
  1001 暂无数据
  2000 服务器错误
  2001 APPID不存在
  2002 商户没有该操作的权限
  2003 参数验证失败
  2004 参数错误或请求超时

响应示例:

{
  "code": "1000", 
  "msg": "操作完成", 
  "result": [
    {
      "VideoCode": "4162657368484", 
      "VideoName": "测试1", 
      "VideoExplain": "加密测试说明1"
    }, 
    {
      "VideoCode": "5161653338483", 
      "VideoName": "测试2", 
      "VideoExplain": "加密测试说明2"
    }
  ]
}

异常示例:

{
  "code": "2000", 
  "msg": "服务器错误"
}

请求代码示例:

$url       = 'https://www.pcwlenv.com/api/GetAllVideoInfo.php';
$appid     = 'XXXXXXXXXXXXXX'; //您的APPID
$appkey    = 'xxxxxxxxxxxxxx'; //您的APPKEY
$method    = 'GetAllVideoInfo'; //授权API的名称
$timestamp = time(); //Unix时间戳,请确保为北京时间
$version   = '1.0'; //授权API的版本
$sign      = sha1($appid . $method . $timestamp . $version . $appkey); //请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
$headers   = array(
	'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
);
$params = array(
	'appid'     => $appid,
	'method'    => $method,
	'timestamp' => $timestamp,
	'version'   => $version,
	'sign'      => $sign
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$json = curl_exec($ch);
curl_close($ch);
echo $json;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class APIDemo {
	public static final String DEF_CHATSET = "UTF-8";
	public static final int DEF_CONN_TIMEOUT = 30000;
	public static final int DEF_READ_TIMEOUT = 30000;
	public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
	public static String ContentType = "application/x-www-form-urlencoded;charset=utf-8";

	private static class TrustAnyTrustManager implements X509TrustManager {
		public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public X509Certificate[] getAcceptedIssuers() {
			return new X509Certificate[] {};
		}
	}

	private static class TrustAnyHostnameVerifier implements HostnameVerifier {
		public boolean verify(String hostname, SSLSession session) {
			return true;
		}
	}

	public static String GetAllVideoInfo() {
		String json = null;
		String url = "https://www.pcwlenv.com/api/GetAllVideoInfo.php";
		String appid = "XXXXXXXXXXXXXX"; // 您的APPID
		String appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY
		String method = "GetAllVideoInfo"; // 授权API的名称
		long timestamp = (long) (System.currentTimeMillis() / 1000); // Unix时间戳,请确保为北京时间
		String version = "1.0"; // 授权API的版本
		String sign = sha1(appid + method + timestamp + version + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
		Map params = new HashMap();
		params.put("appid", appid);
		params.put("method", method);
		params.put("timestamp", timestamp);
		params.put("version", version);
		params.put("sign", sign);
		try {
			json = net(url, params, "POST");
			return json;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 求字符串的SHA1
	public static String sha1(String data) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("SHA1");
		md.update(data.getBytes());
		StringBuffer buf = new StringBuffer();
		byte[] bits = md.digest();
		for (int i = 0; i < bits.length; i++) {
			int a = bits[i];
			if (a < 0)
				a += 256;
			if (a < 16)
				buf.append("0");
			buf.append(Integer.toHexString(a));
		}
		return buf.toString();
	}

	/**
	 *
	 * @param strUrl 请求地址
	 * @param params 请求参数
	 * @param method 请求方法
	 * @return 网络请求字符串
	 * @throws Exception
	 */
	public static String net(String strUrl, Map params, String method) throws Exception {
		HttpsURLConnection conn = null;
		BufferedReader reader = null;
		String rs = null;
		try {
			SSLContext sc = SSLContext.getInstance("SSL");
			sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
			StringBuffer sb = new StringBuffer();
			if (method == null || method.equals("GET")) {
				strUrl = strUrl + "?" + urlencode(params);
			}
			URL url = new URL(strUrl);
			conn = (HttpsURLConnection) url.openConnection();
			if (method == null || method.equals("GET")) {
				conn.setRequestMethod("GET");
			} else {
				conn.setRequestMethod("POST");
				conn.setDoOutput(true);
			}
			conn.setSSLSocketFactory(sc.getSocketFactory());
			conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
			conn.setRequestProperty("Content-Type", ContentType);
			conn.setRequestProperty("User-agent", userAgent);
			conn.setUseCaches(false);
			conn.setConnectTimeout(DEF_CONN_TIMEOUT);
			conn.setReadTimeout(DEF_READ_TIMEOUT);
			conn.setInstanceFollowRedirects(false);
			conn.connect();
			if (params != null && method.equals("POST")) {
				try {
					DataOutputStream out = new DataOutputStream(conn.getOutputStream());
					out.writeBytes(urlencode(params));
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
			InputStream is = conn.getInputStream();
			reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
				sb.append(strRead);
			}
			rs = sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				reader.close();
			}
			if (conn != null) {
				conn.disconnect();
			}
		}
		return rs;
	}

	// 将map型转为请求参数型
	public static String urlencode(Map<String, String> data) {
		StringBuilder sb = new StringBuilder();
		for (Map.Entry i : data.entrySet()) {
			try {
				sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Net; using System.IO; using System.IO.Compression; using System.Text.RegularExpressions; namespace APIDome { class Program { private static readonly string DefaultUserAgent = "Mozilla / 5.0(Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; private static readonly string DefaultContentType = "application/x-www-form-urlencoded;charset=utf-8"; private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; } public static string sha1(string str) { var buffer = Encoding.UTF8.GetBytes(str); var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder(); foreach (var t in data) { sb.Append(t.ToString("X2")); } return sb.ToString(); } public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, Encoding charset) { HttpWebRequest request = null; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version11; request.Proxy = null; request.Method = "POST"; request.ContentType = DefaultContentType; request.UserAgent = DefaultUserAgent; if (!(parameters == null || parameters.Count == 0)) { StringBuilder buffer = new StringBuilder(); int i = 0; foreach (string key in parameters.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, parameters[key]); } else { buffer.AppendFormat("{0}={1}", key, parameters[key]); } i++; } byte[] data = charset.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } } return request.GetResponse() as HttpWebResponse; } static void Main(string[] args) { string url = "https://www.pcwlenv.com/api/GetAllVideoInfo.php"; string appid = "XXXXXXXXXXXXXX"; // 您的APPID string appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY string method = "GetAllVideoInfo"; // 授权API的名称 long timestamp = (long)((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); // Unix时间戳,请确保为北京时间 string version = "1.0"; // 授权API的版本 string sign = Program.sha1(appid + method + timestamp.ToString + version + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后 Encoding encoding = Encoding.GetEncoding("utf-8"); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("appid", appid); parameters.Add("method", method); parameters.Add("timestamp", timestamp); parameters.Add("version", version); parameters.Add("sign", sign); HttpWebResponse response = Program.CreatePostHttpResponse(url, parameters, encoding); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); string json = sr.ReadToEnd(); Console.WriteLine(json); } } }
import ssl
import string
import urllib
import hashlib
import time
import json

url = 'https://www.pcwlenv.com/api/GetAllVideoInfo.php'
appid = 'XXXXXXXXXXXXXX'  #您的APPID
appkey = 'xxxxxxxxxxxxxx'  #您的APPKEY
method = 'GetAllVideoInfo'  #授权API的名称
timestamp = time.time()  #Unix时间戳,请确保为北京时间
version = '1.0'  #授权API的版本
sign = hashlib.sha1(appid + method + timestamp + version + appkey).hexdigest()  #请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
params = {
    'appid': appid,
    'method': method,
    'timestamp': timestamp,
    'version': version,
    'sign': sign
}
context = ssl._create_unverified_context()
headers = {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
}
data = urllib.parse.urlencode(params)
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req, context=context)
content = response.read()
res = json.loads(content)
if res:
    print(res)
else:
    print("请求异常")
接口地址:https://www.pcwlenv.com/api/GetSingleVideoInfo.php
接口说明:根据视频编号获取当前商户的单个加密视频信息。
返回格式:json
请求方式:https post

请求参数说明:

参数 必填 类型 说明 示例值
  appid string 鹏程万里视频加密系统分配给您接入授权API的应用ID PCWL5874647331
  method string 需要调用授权API的名称 GetSingleVideoInfo
  timestamp int 发送请求的Unix时间戳,精确到秒,北京时间误差不超30秒 1555127238
  version string 授权API的版本,该参数值目前固定为1.0 1.0
  videocode int 加密视频编号 5161653338483
  sign string 商户请求参数的签名串,请将所有的请求参数(sign除外)按照顺序组合成一个串,最后组合上您的APPKEY进行sha1加密求值,并赋值给sign参数 81e9209e64bdd3a52fa01ece075eaa947db8fc49

返回参数说明:

参数 类型 说明 示例值
  code string 授权api请求返回码 2000
  msg string 授权api请求返回码描述 服务器错误
  VideoCode int 请求返回的视频编号 5161653338483
  VideoName string 请求返回的视频名称 视频名称测试
  VideoExplain string 请求返回的视频说明 视频说明测试

返回代码说明:

返回码 说明
  1000 操作完成
  1001 暂无数据
  2000 服务器错误
  2001 APPID不存在
  2002 商户没有该操作的权限
  2003 参数验证失败
  2004 参数错误或请求超时

响应示例:

{
  "code": "1000", 
  "msg": "操作完成", 
  "result": [
    {
      "VideoCode": "4162657368484", 
      "VideoName": "测试1", 
      "VideoExplain": "加密测试说明1"
    }
  ]
}

异常示例:

{
  "code": "2000", 
  "msg": "服务器错误"
}

请求代码示例:

$url       = 'https://www.pcwlenv.com/api/GetSingleVideoInfo.php';
$appid     = 'XXXXXXXXXXXXXX'; //您的APPID
$appkey    = 'xxxxxxxxxxxxxx'; //您的APPKEY
$method    = 'GetSingleVideoInfo'; //授权API的名称
$timestamp = time(); //Unix时间戳,请确保为北京时间
$version   = '1.0'; //授权API的版本
$videocode = 5161653338483; //加密视频的编号
$sign      = sha1($appid . $method . $timestamp . $version . $videocode . $appkey); //请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
$headers   = array(
	'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
);
$params = array(
	'appid'     => $appid,
	'method'    => $method,
	'timestamp' => $timestamp,
	'version'   => $version,
	'videocode' => $videocode,
	'sign'      => $sign
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$json = curl_exec($ch);
curl_close($ch);
echo $json;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class APIDemo {
	public static final String DEF_CHATSET = "UTF-8";
	public static final int DEF_CONN_TIMEOUT = 30000;
	public static final int DEF_READ_TIMEOUT = 30000;
	public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
	public static String ContentType = "application/x-www-form-urlencoded;charset=utf-8";

	private static class TrustAnyTrustManager implements X509TrustManager {
		public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public X509Certificate[] getAcceptedIssuers() {
			return new X509Certificate[] {};
		}
	}

	private static class TrustAnyHostnameVerifier implements HostnameVerifier {
		public boolean verify(String hostname, SSLSession session) {
			return true;
		}
	}

	public static String GetSingleVideoInfo() {
		String json = null;
		String url = "https://www.pcwlenv.com/api/GetSingleVideoInfo.php";
		String appid = "XXXXXXXXXXXXXX"; // 您的APPID
		String appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY
		String method = "GetSingleVideoInfo"; // 授权API的名称
		long timestamp = (long) (System.currentTimeMillis() / 1000); // Unix时间戳,请确保为北京时间
		String version = "1.0"; // 授权API的版本
		long videocode = 5161653338483L;// 加密视频的编号
		String sign = sha1(appid + method + timestamp + version + videocode + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
		Map params = new HashMap();
		params.put("appid", appid);
		params.put("method", method);
		params.put("timestamp", timestamp);
		params.put("version", version);
		params.put("videocode", videocode);
		params.put("sign", sign);
		try {
			json = net(url, params, "POST");
			return json;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 求字符串的SHA1
	public static String sha1(String data) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("SHA1");
		md.update(data.getBytes());
		StringBuffer buf = new StringBuffer();
		byte[] bits = md.digest();
		for (int i = 0; i < bits.length; i++) {
			int a = bits[i];
			if (a < 0)
				a += 256;
			if (a < 16)
				buf.append("0");
			buf.append(Integer.toHexString(a));
		}
		return buf.toString();
	}

	/**
	 *
	 * @param strUrl 请求地址
	 * @param params 请求参数
	 * @param method 请求方法
	 * @return 网络请求字符串
	 * @throws Exception
	 */
	public static String net(String strUrl, Map params, String method) throws Exception {
		HttpsURLConnection conn = null;
		BufferedReader reader = null;
		String rs = null;
		try {
			SSLContext sc = SSLContext.getInstance("SSL");
			sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
			StringBuffer sb = new StringBuffer();
			if (method == null || method.equals("GET")) {
				strUrl = strUrl + "?" + urlencode(params);
			}
			URL url = new URL(strUrl);
			conn = (HttpsURLConnection) url.openConnection();
			if (method == null || method.equals("GET")) {
				conn.setRequestMethod("GET");
			} else {
				conn.setRequestMethod("POST");
				conn.setDoOutput(true);
			}
			conn.setSSLSocketFactory(sc.getSocketFactory());
			conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
			conn.setRequestProperty("Content-Type", ContentType);
			conn.setRequestProperty("User-agent", userAgent);
			conn.setUseCaches(false);
			conn.setConnectTimeout(DEF_CONN_TIMEOUT);
			conn.setReadTimeout(DEF_READ_TIMEOUT);
			conn.setInstanceFollowRedirects(false);
			conn.connect();
			if (params != null && method.equals("POST")) {
				try {
					DataOutputStream out = new DataOutputStream(conn.getOutputStream());
					out.writeBytes(urlencode(params));
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
			InputStream is = conn.getInputStream();
			reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
				sb.append(strRead);
			}
			rs = sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				reader.close();
			}
			if (conn != null) {
				conn.disconnect();
			}
		}
		return rs;
	}

	// 将map型转为请求参数型
	public static String urlencode(Map<String, String> data) {
		StringBuilder sb = new StringBuilder();
		for (Map.Entry i : data.entrySet()) {
			try {
				sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Net; using System.IO; using System.IO.Compression; using System.Text.RegularExpressions; namespace APIDome { class Program { private static readonly string DefaultUserAgent = "Mozilla / 5.0(Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; private static readonly string DefaultContentType = "application/x-www-form-urlencoded;charset=utf-8"; private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; } public static string sha1(string str) { var buffer = Encoding.UTF8.GetBytes(str); var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder(); foreach (var t in data) { sb.Append(t.ToString("X2")); } return sb.ToString(); } public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, Encoding charset) { HttpWebRequest request = null; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version11; request.Proxy = null; request.Method = "POST"; request.ContentType = DefaultContentType; request.UserAgent = DefaultUserAgent; if (!(parameters == null || parameters.Count == 0)) { StringBuilder buffer = new StringBuilder(); int i = 0; foreach (string key in parameters.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, parameters[key]); } else { buffer.AppendFormat("{0}={1}", key, parameters[key]); } i++; } byte[] data = charset.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } } return request.GetResponse() as HttpWebResponse; } static void Main(string[] args) { string url = "https://www.pcwlenv.com/api/GetSingleVideoInfo.php"; string appid = "XXXXXXXXXXXXXX"; // 您的APPID string appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY string method = "GetSingleVideoInfo"; // 授权API的名称 long timestamp = (long)((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); // Unix时间戳,请确保为北京时间 string version = "1.0"; // 授权API的版本 long videocode = 5161653338483;// 加密视频的编号 string sign = Program.sha1(appid + method + timestamp.ToString + version + videocode.ToString + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后 Encoding encoding = Encoding.GetEncoding("utf-8"); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("appid", appid); parameters.Add("method", method); parameters.Add("timestamp", timestamp); parameters.Add("version", version); parameters.Add("videocode", videocode); parameters.Add("sign", sign); HttpWebResponse response = Program.CreatePostHttpResponse(url, parameters, encoding); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); string json = sr.ReadToEnd(); Console.WriteLine(json); } } }
import ssl
import string
import urllib
import hashlib
import time
import json

url = 'https://www.pcwlenv.com/api/GetSingleVideoInfo.php'
appid = 'XXXXXXXXXXXXXX'  #您的APPID
appkey = 'xxxxxxxxxxxxxx'  #您的APPKEY
method = 'GetSingleVideoInfo'  #授权API的名称
timestamp = time.time()  #Unix时间戳,请确保为北京时间
version = '1.0'  #授权API的版本
videocode = 5161653338483  #加密视频的编号
sign = hashlib.sha1(appid + method + timestamp + version + videocode + appkey).hexdigest()  #请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
params = {
    'appid': appid,
    'method': method,
    'timestamp': timestamp,
    'version': version,
    'videocode': videocode,
    'sign': sign
}
context = ssl._create_unverified_context()
headers = {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
}
data = urllib.parse.urlencode(params)
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req, context=context)
content = response.read()
res = json.loads(content)
if res:
    print(res)
else:
    print("请求异常")
接口地址:https://www.pcwlenv.com/api/AddUserAuthority.php
接口说明:添加一个播放用户授权,每添加一个播放用户授权会自动扣除一个授权点数,请保证您的授权点数充足,如果您的授权点数为0,授权API将无法完成请求。
返回格式:json
请求方式:https post

请求参数说明:

参数 必填 类型 说明 示例值
  appid string 鹏程万里视频加密系统分配给您接入授权API的应用ID PCWL5874647331
  method string 需要调用授权API的名称 AddUserAuthority
  timestamp int 发送请求的Unix时间戳,精确到秒,北京时间误差不超30秒 1555127238
  version string 授权API的版本,该参数值目前固定为1.0 1.0
  videocode int 加密视频编号 5161653338483
  hardwareid string 需要添加播放授权的用户硬件识别码 ABAB-CACA-DBDB-BVBV
  username string 需要添加播放授权的用户名水印,会显示在播放器上 用户名水印
  usertype int 需要添加播放授权的用户类型,此值必须为0 0
  userplaynum int 需要添加播放授权的用户播放次数 99999
  userexpiredtime string 需要添加播放授权的用户过期时间,请以格式为“YYYY-MM-DD”或“YYYY-MM-DD HH:MM:SS”进行赋值 2019-01-01 或 2019-01-01 20:30:40
  sign string 商户请求参数的签名串,请将所有的请求参数(sign除外)按照顺序组合成一个串,最后组合上您的APPKEY进行sha1加密求值,并赋值给sign参数 81e9209e64bdd3a52fa01ece075eaa947db8fc49

返回参数说明:

参数 类型 说明 示例值
  code string 授权api请求返回码 2000
  msg string 授权api请求返回码描述 服务器错误
  videocode int 请求返回的视频编号 5161653338483
  videoname string 请求返回的视频名称 测试

返回代码说明:

返回码 说明
  1000 添加授权成功
  1001 授权添加失败,请稍候再试
  1002 该视频授权已在服务器上存在
  2000 服务器错误
  2001 APPID不存在
  2002 商户没有该操作的权限
  2003 参数验证失败
  2004 参数错误或请求超时
  2005 该视频编号不存在
  2006 商户授权点数已不足
  2007 系统繁忙,请稍后再试

响应示例:

{
  "code": "1000", 
  "msg": "操作完成", 
  "videocode": "5161653338483", 
  "videoname": "测试"
}

异常示例:

{
  "code": "2000", 
  "msg": "服务器错误"
}

请求代码示例:

$url             = 'https://www.pcwlenv.com/api/AddUserAuthority.php';
$appid           = 'XXXXXXXXXXXXXX'; //您的APPID
$appkey          = 'xxxxxxxxxxxxxx'; //您的APPKEY
$method          = 'AddUserAuthority'; //授权API的名称
$timestamp       = time(); //Unix时间戳,请确保为北京时间
$version         = '1.0'; //授权API的版本
$videocode       = 5161653338483; //加密视频的编号
$hardwareid      = 'xxxx-xxxx-xxxx-xxxx'; //播放授权的用户硬件识别码
$username        = 'qq453188691'; //播放授权的用户名水印,会显示在播放器上
$usertype        = 0; //播放授权的用户类型,此值必须为0
$userplaynum     = 99999; //播放授权的用户播放次数
$userexpiredtime = 'YYYY-MM-DD hh:mm:ss'; //播放授权的用户过期时间,请以格式为“YYYY-MM-DD”或“YYYY-MM-DD HH:MM:SS”进行赋值
$sign            = sha1($appid . $method . $timestamp . $version . $videocode . $hardwareid . $username . $usertype . $userplaynum . $userexpiredtime . $appkey); //请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
$headers         = array(
	'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
);
$params = array(
	'appid'           => $appid,
	'method'          => $method,
	'timestamp'       => $timestamp,
	'version'         => $version,
	'videocode'       => $videocode,
	'hardwareid'      => $hardwareid,
	'username'        => $username,
	'usertype'        => $usertype,
	'userplaynum'     => $userplaynum,
	'userexpiredtime' => $userexpiredtime,
	'sign'            => $sign
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$json = curl_exec($ch);
curl_close($ch);
echo $json;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class APIDemo {
	public static final String DEF_CHATSET = "UTF-8";
	public static final int DEF_CONN_TIMEOUT = 30000;
	public static final int DEF_READ_TIMEOUT = 30000;
	public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
	public static String ContentType = "application/x-www-form-urlencoded;charset=utf-8";

	private static class TrustAnyTrustManager implements X509TrustManager {
		public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public X509Certificate[] getAcceptedIssuers() {
			return new X509Certificate[] {};
		}
	}

	private static class TrustAnyHostnameVerifier implements HostnameVerifier {
		public boolean verify(String hostname, SSLSession session) {
			return true;
		}
	}

	public static String AddUserAuthority() {
		String json = null;
		String url = "https://www.pcwlenv.com/api/AddUserAuthority.php";
		String appid = "XXXXXXXXXXXXXX"; // 您的APPID
		String appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY
		String method = "AddUserAuthority"; // 授权API的名称
		long timestamp = (long) (System.currentTimeMillis() / 1000); // Unix时间戳,请确保为北京时间
		String version = "1.0"; // 授权API的版本
		long videocode = 5161653338483L;// 加密视频的编号
		String hardwareid = "xxxx-xxxx-xxxx-xxxx"; // 播放授权的用户硬件识别码
		String username = "qq453188691"; // 播放授权的用户名水印,会显示在播放器上
		int usertype = 0; // 播放授权的用户类型,此值必须为0
		int userplaynum = 99999; // 播放授权的用户播放次数
		String userexpiredtime = "YYYY-MM-DD hh:mm:ss"; // 播放授权的用户过期时间,请以格式为“YYYY-MM-DD”或“YYYY-MM-DD HH:MM:SS”进行赋值
		String sign = sha1(appid + method + timestamp + version + videocode + hardwareid + username + usertype + userplaynum + userexpiredtime + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
		Map params = new HashMap();
		params.put("appid", appid);
		params.put("method", method);
		params.put("timestamp", timestamp);
		params.put("version", version);
		params.put("videocode", videocode);
		params.put("hardwareid", hardwareid);
		params.put("username", username);
		params.put("usertype", usertype);
		params.put("userplaynum", userplaynum);
		params.put("userexpiredtime", userexpiredtime);
		params.put("sign", sign);
		try {
			json = net(url, params, "POST");
			return json;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 求字符串的SHA1
	public static String sha1(String data) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("SHA1");
		md.update(data.getBytes());
		StringBuffer buf = new StringBuffer();
		byte[] bits = md.digest();
		for (int i = 0; i < bits.length; i++) {
			int a = bits[i];
			if (a < 0)
				a += 256;
			if (a < 16)
				buf.append("0");
			buf.append(Integer.toHexString(a));
		}
		return buf.toString();
	}

	/**
	 *
	 * @param strUrl 请求地址
	 * @param params 请求参数
	 * @param method 请求方法
	 * @return 网络请求字符串
	 * @throws Exception
	 */
	public static String net(String strUrl, Map params, String method) throws Exception {
		HttpsURLConnection conn = null;
		BufferedReader reader = null;
		String rs = null;
		try {
			SSLContext sc = SSLContext.getInstance("SSL");
			sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
			StringBuffer sb = new StringBuffer();
			if (method == null || method.equals("GET")) {
				strUrl = strUrl + "?" + urlencode(params);
			}
			URL url = new URL(strUrl);
			conn = (HttpsURLConnection) url.openConnection();
			if (method == null || method.equals("GET")) {
				conn.setRequestMethod("GET");
			} else {
				conn.setRequestMethod("POST");
				conn.setDoOutput(true);
			}
			conn.setSSLSocketFactory(sc.getSocketFactory());
			conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
			conn.setRequestProperty("Content-Type", ContentType);
			conn.setRequestProperty("User-agent", userAgent);
			conn.setUseCaches(false);
			conn.setConnectTimeout(DEF_CONN_TIMEOUT);
			conn.setReadTimeout(DEF_READ_TIMEOUT);
			conn.setInstanceFollowRedirects(false);
			conn.connect();
			if (params != null && method.equals("POST")) {
				try {
					DataOutputStream out = new DataOutputStream(conn.getOutputStream());
					out.writeBytes(urlencode(params));
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
			InputStream is = conn.getInputStream();
			reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
				sb.append(strRead);
			}
			rs = sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				reader.close();
			}
			if (conn != null) {
				conn.disconnect();
			}
		}
		return rs;
	}

	// 将map型转为请求参数型
	public static String urlencode(Map<String, String> data) {
		StringBuilder sb = new StringBuilder();
		for (Map.Entry i : data.entrySet()) {
			try {
				sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Net; using System.IO; using System.IO.Compression; using System.Text.RegularExpressions; namespace APIDome { class Program { private static readonly string DefaultUserAgent = "Mozilla / 5.0(Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; private static readonly string DefaultContentType = "application/x-www-form-urlencoded;charset=utf-8"; private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; } public static string sha1(string str) { var buffer = Encoding.UTF8.GetBytes(str); var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder(); foreach (var t in data) { sb.Append(t.ToString("X2")); } return sb.ToString(); } public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, Encoding charset) { HttpWebRequest request = null; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version11; request.Proxy = null; request.Method = "POST"; request.ContentType = DefaultContentType; request.UserAgent = DefaultUserAgent; if (!(parameters == null || parameters.Count == 0)) { StringBuilder buffer = new StringBuilder(); int i = 0; foreach (string key in parameters.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, parameters[key]); } else { buffer.AppendFormat("{0}={1}", key, parameters[key]); } i++; } byte[] data = charset.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } } return request.GetResponse() as HttpWebResponse; } static void Main(string[] args) { string url = "https://www.pcwlenv.com/api/AddUserAuthority.php"; string appid = "XXXXXXXXXXXXXX"; // 您的APPID string appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY string method = "AddUserAuthority"; // 授权API的名称 long timestamp = (long)((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); // Unix时间戳,请确保为北京时间 string version = "1.0"; // 授权API的版本 long videocode = 5161653338483;// 加密视频的编号 string hardwareid = "xxxx-xxxx-xxxx-xxxx"; // 播放授权的用户硬件识别码 string username = "qq453188691"; // 播放授权的用户名水印,会显示在播放器上 int usertype = 0; // 播放授权的用户类型,此值必须为0 int userplaynum = 99999; // 播放授权的用户播放次数 string userexpiredtime = "YYYY-MM-DD hh:mm:ss"; // 播放授权的用户过期时间,请以格式为“YYYY-MM-DD”或“YYYY-MM-DD HH:MM:SS”进行赋值 string sign = Program.sha1(appid + method + timestamp + version + videocode + hardwareid + username + usertype + userplaynum + userexpiredtime + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后 Encoding encoding = Encoding.GetEncoding("utf-8"); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("appid", appid); parameters.Add("method", method); parameters.Add("timestamp", timestamp); parameters.Add("version", version); parameters.Add("videocode", videocode); parameters.Add("hardwareid", hardwareid); parameters.Add("username", username); parameters.Add("usertype", usertype); parameters.Add("userplaynum", userplaynum); parameters.Add("userexpiredtime", userexpiredtime); parameters.Add("sign", sign); HttpWebResponse response = Program.CreatePostHttpResponse(url, parameters, encoding); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); string json = sr.ReadToEnd(); Console.WriteLine(json); } } }
import ssl
import string
import urllib
import hashlib
import time
import json

url = 'https://www.pcwlenv.com/api/AddUserAuthority.php'
appid = 'XXXXXXXXXXXXXX'  #您的APPID
appkey = 'xxxxxxxxxxxxxx'  #您的APPKEY
method = 'AddUserAuthority'  #授权API的名称
timestamp = time.time()  #Unix时间戳,请确保为北京时间
version = '1.0'  #授权API的版本
videocode = 5161653338483  #加密视频的编号
hardwareid = 'xxxx-xxxx-xxxx-xxxx'  #播放授权的用户硬件识别码
username = 'qq453188691'  #播放授权的用户名水印,会显示在播放器上
usertype = 0  #播放授权的用户类型,此值必须为0
userplaynum = 99999  #播放授权的用户播放次数
userexpiredtime = 'YYYY-MM-DD hh:mm:ss'  #播放授权的用户过期时间,请以格式为“YYYY-MM-DD”或“YYYY-MM-DD HH:MM:SS”进行赋值
sign = hashlib.sha1(appid + method + timestamp + version + videocode + hardwareid + username + usertype + userplaynum + userexpiredtime + appkey).hexdigest()  #请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
params = {
    'appid': appid,
    'method': method,
    'timestamp': timestamp,
    'version': version,
    'videocode': videocode,
    'hardwareid': hardwareid,
    'username': username,
    'usertype': usertype,
    'userplaynum': userplaynum,
    'userexpiredtime': userexpiredtime,
    'sign': sign
}
context = ssl._create_unverified_context()
headers = {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
}
data = urllib.parse.urlencode(params)
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req, context=context)
content = response.read()
res = json.loads(content)
if res:
    print(res)
else:
    print("请求异常")
接口地址:https://www.pcwlenv.com/api/GetActivationCode.php
接口说明:给播放用户发放一个或多个视频激活码,请确保视频激活码的库存量充足,如果视频激活码的库存量不足,授权API将无法完成请求。视频激活码请在加密系统的 批量授权管理 里添加。
返回格式:json
请求方式:https post

请求参数说明:

参数 必填 类型 说明 示例值
  appid string 鹏程万里视频加密系统分配给您接入授权API的应用ID PCWL5874647331
  method string 需要调用授权API的名称 GetActivationCode
  timestamp int 发送请求的Unix时间戳,精确到秒,北京时间误差不超30秒 1555127238
  version string 授权API的版本,该参数值目前固定为1.0 1.0
  videocode int 加密视频编号 5161653338483
  codenum int 需要取出授权码的数量 1
  authtime 可选 string 用户使用激活码时,激活授权的时间。填写格式:比如 5Y = 5年,5M = 5月,5D = 5天。默认为 5Y。 5Y
  playnum 可选 int 用户使用激活码时,激活授权的播放次数。默认为 99999 次。 99999
  username 可选 string 激活码绑定的用户名,用户名作为视频水印使用 鹏程万里视频加密
  sign string 商户请求参数的签名串,请将所有的请求参数(sign除外)按照顺序组合成一个串,最后组合上您的APPKEY进行sha1加密求值,并赋值给sign参数 81e9209e64bdd3a52fa01ece075eaa947db8fc49

返回参数说明:

参数 类型 说明 示例值
  code string 授权api请求返回码 2000
  msg string 授权api请求返回码描述 服务器错误
  codenum int 请求返回的视频激活码数量 1
  videocode int 请求返回的视频编号 5161653338483
  videoname string 请求返回的视频名称 测试
  ActivateNUM string 请求返回的视频激活码 0F13F2-FBFD5-3A2B7-4FA3B-87DD6-CDBD05-5Y99999

返回代码说明:

返回码 说明
  1000 操作完成
  1001 该视频激活码库存已不足
  2000 服务器错误
  2001 APPID不存在
  2002 商户没有该操作的权限
  2003 参数验证失败
  2004 参数错误或请求超时
  2005 该视频编号不存在
  2006 系统繁忙,请稍后再试

响应示例:

{
  "code": "1000", 
  "msg": "操作完成", 
  "codenum": "1", 
  "videocode": "5161653338483", 
  "videoname": "测试", 
  "result": [
    {
      "ActivateNUM": "0F13F2-FBFD5-3A2B7-4FA3B-87DD6-CDBD05-5Y99999"
    }
  ]
}

异常示例:

{
  "code": "2000", 
  "msg": "服务器错误"
}

请求代码示例:

$url       = 'https://www.pcwlenv.com/api/GetActivationCode.php';
$appid     = 'XXXXXXXXXXXXXX'; //您的APPID
$appkey    = 'xxxxxxxxxxxxxx'; //您的APPKEY
$method    = 'GetActivationCode'; //授权API的名称
$timestamp = time(); //Unix时间戳,请确保为北京时间
$version   = '1.0'; //授权API的版本
$videocode = 5161653338483; //加密视频的编号
$codenum   = 1; //取出授权码的数量
$sign      = sha1($appid . $method . $timestamp . $version . $videocode . $codenum . $appkey); //请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
$headers   = array(
	'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
);
$params = array(
	'appid'     => $appid,
	'method'    => $method,
	'timestamp' => $timestamp,
	'version'   => $version,
	'videocode' => $videocode,
	'codenum'   => $codenum,
	'sign'      => $sign
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$json = curl_exec($ch);
curl_close($ch);
echo $json;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class APIDemo {
	public static final String DEF_CHATSET = "UTF-8";
	public static final int DEF_CONN_TIMEOUT = 30000;
	public static final int DEF_READ_TIMEOUT = 30000;
	public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
	public static String ContentType = "application/x-www-form-urlencoded;charset=utf-8";

	private static class TrustAnyTrustManager implements X509TrustManager {
		public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
		}

		public X509Certificate[] getAcceptedIssuers() {
			return new X509Certificate[] {};
		}
	}

	private static class TrustAnyHostnameVerifier implements HostnameVerifier {
		public boolean verify(String hostname, SSLSession session) {
			return true;
		}
	}

	public static String GetActivationCode() {
		String json = null;
		String url = "https://www.pcwlenv.com/api/GetActivationCode.php";
		String appid = "XXXXXXXXXXXXXX"; // 您的APPID
		String appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY
		String method = "GetActivationCode"; // 授权API的名称
		long timestamp = (long) (System.currentTimeMillis() / 1000); // Unix时间戳,请确保为北京时间
		String version = "1.0"; // 授权API的版本
		long videocode = 5161653338483L;// 加密视频的编号
		int codenum   = 1; //取出授权码的数量
		String sign = sha1(appid + method + timestamp + version + videocode + codenum + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
		Map params = new HashMap();
		params.put("appid", appid);
		params.put("method", method);
		params.put("timestamp", timestamp);
		params.put("version", version);
		params.put("videocode", videocode);
		params.put("codenum", codenum);
		params.put("sign", sign);
		try {
			json = net(url, params, "POST");
			return json;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 求字符串的SHA1
	public static String sha1(String data) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("SHA1");
		md.update(data.getBytes());
		StringBuffer buf = new StringBuffer();
		byte[] bits = md.digest();
		for (int i = 0; i < bits.length; i++) {
			int a = bits[i];
			if (a < 0)
				a += 256;
			if (a < 16)
				buf.append("0");
			buf.append(Integer.toHexString(a));
		}
		return buf.toString();
	}

	/**
	 *
	 * @param strUrl 请求地址
	 * @param params 请求参数
	 * @param method 请求方法
	 * @return 网络请求字符串
	 * @throws Exception
	 */
	public static String net(String strUrl, Map params, String method) throws Exception {
		HttpsURLConnection conn = null;
		BufferedReader reader = null;
		String rs = null;
		try {
			SSLContext sc = SSLContext.getInstance("SSL");
			sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
			StringBuffer sb = new StringBuffer();
			if (method == null || method.equals("GET")) {
				strUrl = strUrl + "?" + urlencode(params);
			}
			URL url = new URL(strUrl);
			conn = (HttpsURLConnection) url.openConnection();
			if (method == null || method.equals("GET")) {
				conn.setRequestMethod("GET");
			} else {
				conn.setRequestMethod("POST");
				conn.setDoOutput(true);
			}
			conn.setSSLSocketFactory(sc.getSocketFactory());
			conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
			conn.setRequestProperty("Content-Type", ContentType);
			conn.setRequestProperty("User-agent", userAgent);
			conn.setUseCaches(false);
			conn.setConnectTimeout(DEF_CONN_TIMEOUT);
			conn.setReadTimeout(DEF_READ_TIMEOUT);
			conn.setInstanceFollowRedirects(false);
			conn.connect();
			if (params != null && method.equals("POST")) {
				try {
					DataOutputStream out = new DataOutputStream(conn.getOutputStream());
					out.writeBytes(urlencode(params));
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
			InputStream is = conn.getInputStream();
			reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
				sb.append(strRead);
			}
			rs = sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				reader.close();
			}
			if (conn != null) {
				conn.disconnect();
			}
		}
		return rs;
	}

	// 将map型转为请求参数型
	public static String urlencode(Map<String, String> data) {
		StringBuilder sb = new StringBuilder();
		for (Map.Entry i : data.entrySet()) {
			try {
				sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Net; using System.IO; using System.IO.Compression; using System.Text.RegularExpressions; namespace APIDome { class Program { private static readonly string DefaultUserAgent = "Mozilla / 5.0(Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; private static readonly string DefaultContentType = "application/x-www-form-urlencoded;charset=utf-8"; private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; } public static string sha1(string str) { var buffer = Encoding.UTF8.GetBytes(str); var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder(); foreach (var t in data) { sb.Append(t.ToString("X2")); } return sb.ToString(); } public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, Encoding charset) { HttpWebRequest request = null; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version11; request.Proxy = null; request.Method = "POST"; request.ContentType = DefaultContentType; request.UserAgent = DefaultUserAgent; if (!(parameters == null || parameters.Count == 0)) { StringBuilder buffer = new StringBuilder(); int i = 0; foreach (string key in parameters.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, parameters[key]); } else { buffer.AppendFormat("{0}={1}", key, parameters[key]); } i++; } byte[] data = charset.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } } return request.GetResponse() as HttpWebResponse; } static void Main(string[] args) { string url = "https://www.pcwlenv.com/api/GetActivationCode.php"; string appid = "XXXXXXXXXXXXXX"; // 您的APPID string appkey = "xxxxxxxxxxxxxx"; // 您的APPKEY string method = "GetActivationCode"; // 授权API的名称 long timestamp = (long)((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); // Unix时间戳,请确保为北京时间 string version = "1.0"; // 授权API的版本 long videocode = 5161653338483;// 加密视频的编号 int codenum = 1; //取出授权码的数量 string sign = Program.sha1(appid + method + timestamp + version + videocode + codenum + appkey); // 请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后 Encoding encoding = Encoding.GetEncoding("utf-8"); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("appid", appid); parameters.Add("method", method); parameters.Add("timestamp", timestamp); parameters.Add("version", version); parameters.Add("videocode", videocode); parameters.Add("codenum", codenum); parameters.Add("sign", sign); HttpWebResponse response = Program.CreatePostHttpResponse(url, parameters, encoding); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); string json = sr.ReadToEnd(); Console.WriteLine(json); } } }
import ssl
import string
import urllib
import hashlib
import time
import json

url = 'https://www.pcwlenv.com/api/GetActivationCode.php'
appid = 'XXXXXXXXXXXXXX'  #您的APPID
appkey = 'xxxxxxxxxxxxxx'  #您的APPKEY
method = 'GetActivationCode'  #授权API的名称
timestamp = time.time()  #Unix时间戳,请确保为北京时间
version = '1.0'  #授权API的版本
videocode = 5161653338483  #加密视频的编号
codenum = 1  #取出授权码的数量
sign = hashlib.sha1(appid + method + timestamp + version + videocode + codenum + appkey).hexdigest()  #请求参数的签名串,按照参数的顺序用sha1加密,APPKEY放到最后
params = {
    'appid': appid,
    'method': method,
    'timestamp': timestamp,
    'version': version,
    'videocode': videocode,
    'codenum': codenum,
    'sign': sign
}
context = ssl._create_unverified_context()
headers = {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
}
data = urllib.parse.urlencode(params)
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req, context=context)
content = response.read()
res = json.loads(content)
if res:
    print(res)
else:
    print("请求异常")

联系我们

播放端售后服务QQ群: 99685605
工作时间: 9:00-23:00

客服QQ: 3383273386
工作时间: 9:00-23:00

E-mail和微信(点击微信图标扫码): support@pcwlenv.com