m0_73955310 2023-08-13 14:25 采纳率: 50%
浏览 25
已结题

这几句PHP代码,用ASP怎么写

这几句PHP代码,用ASP应该怎么写
ksort($params);
$str = urldecode(http_build_query($params));
$hash = mhash(MHASH_SHA256, $str, $keycode);
$params['sign'] = base64_encode($hash);
$url = "https://open.huawa.com/newapi/import%22;
$data = http_post($url, $params);

  • 写回答

9条回答 默认 最新

  • threenewbee 2023-08-13 14:28
    关注
    获得1.50元问题酬金

    这是对参数签名吧,需要调用SHA256

    <%@ Language=VBScript %>
    <%
    ' Sorting the params dictionary
    Set params = CreateObject("Scripting.Dictionary")
    For Each x In Request.Form
        params(x) = Request.Form(x)
    Next
    Set keys = params.Keys
    keys.Sort
    
    ' Building the query string
    str = ""
    For Each key In keys
        val = Server.UrlEncode(params(key))
        If str <> "" Then
            str = str & "&"
        End If
        str = str & key & "=" & val
    Next
    
    ' Calculating the hash
    Set crypto = Server.CreateObject("CAPICOM.HashedData")
    crypto.Algorithm = 8  ' SHA-256
    crypto.SignedData = str & "&" & keycode
    hash = crypto.Value
    
    ' Encoding the hash with base64
    Set base64 = Server.CreateObject("MSXML2.DomDocument")
    Set elem = base64.CreateElement("base64")
    elem.DataType = "bin.base64"
    elem.NodeTypedValue = hash
    encoded = elem.Text
    
    ' Adding the sign parameter
    params("sign") = encoded
    
    ' Sending the POST request
    Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
    url = "https://open.huawa.com/newapi/import"
    http.Open "POST", url, False
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.Send str
    
    ' Receiving the response
    responseText = http.responseText
    Response.Write responseText
    %>
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 8月21日
  • 创建了问题 8月13日

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题