-
public static string Post(string method, string jsonData, string merchantNo, string merchantKey)
{
string postUrl = string.Concat(rootUrl, method); //rootUrl:"HTTPS://API.LianKeOnline.COM/QuickPay/",method:"Pay"
byte[] bytes = Encoding.UTF8.GetBytes(jsonData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
if (!string.IsNullOrEmpty(merchantNo))
{
string timeStamp = GetTimeStamp();
string nonce = GetRandom();
//加入头信息
request.Headers.Add("merchantno", merchantNo); //当前请求商户编码
request.Headers.Add("merchantkey", merchantKey); //当前请求商户秘钥
request.Headers.Add("timestamp", timeStamp); //发起请求时的时间戳(单位:毫秒)
request.Headers.Add("nonce", nonce); //随机数
request.Headers.Add("signature", GetSignature(timeStamp, nonce, merchantNo, merchantKey, jsonData)); //当前请求内容的数字签名
}
//写数据
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "application/json";
Stream reqstream = request.GetRequestStream();
reqstream.Write(bytes, 0, bytes.Length);
//读数据
request.Timeout = 30000;
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
StreamReader streamReader = new StreamReader(streamReceive, Encoding.UTF8);
string strResult = streamReader.ReadToEnd();
//关闭流
reqstream.Close();
streamReader.Close();
streamReceive.Close();
request.Abort();
response.Close();
return strResult;
}
-
public static String Post(String method, String jsonData, String merchantNo, String merchantKey)
{
url = String.Concat(rootUrl, method);
byte[] bytes = Encoding.UTF8.GetBytes(jsonData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
if(merchantNo!=null && !merchantNo.equals(""))
{
String timeStamp = GetTimeStamp();
String nonce = GetRandom();
//加入头信息
request.Headers.Add("merchantno", merchantNo); //当前请求商户编码
request.Headers.Add("merchantkey", merchantKey); //当前请求商户秘钥
request.Headers.Add("timestamp", timeStamp); //发起请求时的时间戳(单位:毫秒)
request.Headers.Add("nonce", nonce); //随机数
request.Headers.Add("signature", GetSignature(timeStamp, nonce, merchantNo, merchantKey, jsonData)); //当前请求内容的数字签名
}
//写数据
request.Method = "POST";
request.ContentLength = bytes.length;
request.ContentType = "application/json";
Stream reqstream = request.GetRequestStream();
reqstream.Write(bytes, 0, bytes.length);
//读数据
request.Timeout = 30000;
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
StreamReader streamReader = new StreamReader(streamReceive, Encoding.UTF8);
String strResult = streamReader.ReadToEnd();
//关闭流
reqstream.Close();
streamReader.Close();
streamReceive.Close();
request.Abort();
response.Close();
return strResult;
}
-
function post($method, $postdata, $merchantNo, $merchantKey)
{
$url = $rooturl . $method
//添加header信息
$header = [
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData),
];
$timestamp = time().'000'
$nonce = generateNonceStr()
$header = [
'merchantno' => $merchantNo,
'merchantkey' => $merchantKey,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => getsignature($timestamp,$nonce,$merchantno,$merchantkey,$postdata),
];
if ($optionHeader) {
foreach ($optionHeader as $k => $v) {
$header[] = $k . ': '.$v;
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//发送post信息
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonParams);
//发送header
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}