Ionic 如何从帖子中提取表单数据

bvuwiixz  于 2022-12-09  发布在  Ionic
关注(0)|答案(2)|浏览(166)

我的支付网关已向我的网站发送了一个帖子,其中包含this form-data信息。
我尝试检索数据为:

this.http
  .post<any>('https://xyz.app/test', {
    title: 'Testing...',
  })
  .subscribe((data) => {      
    console.log(data);
  });

但没有成功.就像我得到下面的呓语内容和错误一样:

Unexpected error occurred
{
  "headers": {
    "normalizedNames": {},
    "lazyUpdate": null
  },
  "status": 200,
  "statusText": "OK",
  "url": "https://xyz.app/test",
  "ok": false,
  "name": "HttpErrorResponse",
  "message": "Http failure during parsing for https://xyz.app/test",
  "error": {
    "error": {},
    "text": "<!DOCTYPE html><html lang=\"en\"><head>\n    <meta charset=\"utf-8\">\n    <title>xyz</title>\n\n    <base href=\"/\">\n\n    <meta name=\"viewport\" content=\"viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n    <meta name=\"format-detection\" content=\"telephone=no\">\n    <meta name=\"msapplication-tap-highlight\" content=\"no\">\n    <meta name=\"color-scheme\" content=\"light\">\n\n    <link rel=\"icon\" type=\"image/png\" href=\"assets/icon/favicon.png\">\n\n    <!-- add to homescreen for ios -->\n    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n    <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\">\n\n     <style>:root{--ion-color-primary:#5260ff;--ion-color-primary-rgb:82, 96, 255;--ion-color-primary-contrast:#ffffff;--ion-color-primary-contrast-rgb:255, 255, 255;--ion-color-primary-shade:#4854e0;--ion-color-primary-tint:#6370ff;--ion-color-secondary:#3dc2ff;--ion-color-secondary-rgb:61, 194, 255;--ion-color-secondary-contrast:#ffffff;--ion-color-secondary-contrast-rgb:255, 255, 255;--ion-color-secondary-shade:#36abe0;--ion-color-secondary-tint:#50c8ff;--ion-color-tertiary:#5260ff;--ion-color-tertiary-rgb:82, 96, 255;--ion-color-tertiary-contrast:#ffffff;--ion-color-tertiary-contrast-rgb:255, 255, 255;--ion-color-tertiary-shade:#4854e0;--ion-color-tertiary-tint:#6370ff;--ion-color-success:#2dd36f;--ion-color-success-rgb:45, 211, 111;--ion-color-success-contrast:#ffffff;--ion-color-success-contrast-rgb:255, 255, 255;--ion-color-success-shade:#28ba62;--ion-color-success-tint:#42d77d;--ion-color-warning:#ffc409;--ion-color-warning-rgb:255, 196, 9;--ion-color-warning-contrast:#000000;--ion-color-warning-contrast-rgb:0, 0, 0;--ion-color-warning-shade:#e0ac08;--ion-color-warning-tint:#ffca22;--ion-color-danger:#eb445a;--ion-color-danger-rgb:235, 68, 90;--ion-color-danger-contrast:#ffffff;--ion-color-danger-contrast-rgb:255, 255, 255;--ion-color-danger-shade:#cf3c4f;--ion-color-danger-tint:#ed576b;--ion-color-dark:#222428;--ion-color-dark-rgb:34, 36, 40;--ion-color-dark-contrast:#ffffff;--ion-color-dark-contrast-rgb:255, 255, 255;--ion-color-dark-shade:#1e2023;--ion-color-dark-tint:#383a3e;--ion-color-medium:#92949c;--ion-color-medium-rgb:146, 148, 156;--ion-color-medium-contrast:#ffffff;--ion-color-medium-contrast-rgb:255, 255, 255;--ion-color-medium-shade:#808289;--ion-color-medium-tint:#9d9fa6;--ion-color-light:#f4f5f8;--ion-color-light-rgb:244, 245, 248;--ion-color-light-contrast:#000000;--ion-color-light-contrast-rgb:0, 0, 0;--ion-color-light-shade:#d7d8da;--ion-color-light-tint:#f5f6f9}html{--ion-font-family:var(--ion-default-font)}body{background:var(--ion-background-color)}@supports (padding-top: 20px){html{--ion-safe-area-top:var(--ion-statusbar-padding)}}@supports (padding-top: constant(safe-area-inset-top)){html{--ion-safe-area-top:constant(safe-area-inset-top);--ion-safe-area-bottom:constant(safe-area-inset-bottom);--ion-safe-area-left:constant(safe-area-inset-left);--ion-safe-area-right:constant(safe-area-inset-right)}}@supports (padding-top: env(safe-area-inset-top)){html{--ion-safe-area-top:env(safe-area-inset-top);--ion-safe-area-bottom:env(safe-area-inset-bottom);--ion-safe-area-left:env(safe-area-inset-left);--ion-safe-area-right:env(safe-area-inset-right)}}*{box-sizing:border-box;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}html{width:100%;height:100%;-webkit-text-size-adjust:100%;text-size-adjust:100%}html:not(.hydrated) body{display:none}body{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;margin:0;padding:0;position:fixed;width:100%;max-width:100%;height:100%;max-height:100%;text-rendering:optimizeLegibility;overflow:hidden;touch-action:manipulation;-webkit-user-drag:none;-ms-content-zooming:none;word-wrap:break-word;overscroll-behavior-y:none;-webkit-text-size-adjust:none;text-size-adjust:none}html{font-family:var(--ion-font-family)}@charset \"UTF-8\"</style><link rel=\"stylesheet\" href=\"styles.bc92802669c0456a.css\" media=\"print\" onload=\"this.media='all'\"><noscript><link rel=\"stylesheet\" href=\"styles.bc92802669c0456a.css\"></noscript></head>\n\n  <body>\n    <app-root></app-root>\n  <script src=\"runtime.a2227e7648f5402e.js\" type=\"module\"></script><script src=\"polyfills.272ca3dbf05a7a8c.js\" type=\"module\"></script><script src=\"main.9b185556f2c0b4c3.js\" type=\"module\"></script>\n\n</body></html>"
  }
}

另一个错误:

ERROR 
ke {headers: E, status: 200, statusText: 'OK', url: 'https://xyz.app/test', ok: false, …}
error: {error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHtt…, text: '<!DOCTYPE html><html lang="en"><head>\n    <meta ch…0b4c3.js" type="module">\x3C/script>\n\n</body></html>'}
headers: E {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure during parsing for https://xyz.app/test"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "https://xyz.app/test"
[[Prototype]]: Oe
constructor: class ke
[[Prototype]]: Object

我想检索付款交易数据,稍后再显示它。
支付网关发送给我一个PHP代码:〈?php

function verifychecksum_eFromStr($str, $key, $checksumvalue) {  
    $sadad_hash = decrypt_e($checksumvalue, $key); 
    $salt = substr($sadad_hash, -4); 
    $finalString = $str . "|" . $salt; 
    $website_hash = hash("sha256", $finalString); 
    $website_hash .= $salt; 
    $validFlag = "FALSE"; 
    if ($website_hash == $sadad_hash) { 
    $validFlag = "TRUE"; 
    } else { 
    $validFlag = "FALSE"; 
    } 
    return $validFlag; 
    } 
    function decrypt_e($crypt, $ky) { 
    $ky = html_entity_decode($ky); 
    $iv = "@@@@&&&&####$$$$"; 
    $data = openssl_decrypt($crypt, "AES-128-CBC", $ky, 0, $iv);  return $data; 
    } 

    $merchantId = '1234657'; //Replace with your merchant ID
    $secretKey = 'XXXXXXXXXXXXXXX'; //Replace with your secret Key
    
    //Save incoming checksumhash into a variable and then unset it because we don't use it while verifying the checksum
    $checksum_response = $_POST['checksumhash'];
    unset($_POST['checksumhash']); 
     
    $data_repsonse = array();  
    $data_repsonse['postData'] = $_POST;  //Incoming POST without checksumhash in it. 
    $data_repsonse['secretKey'] = $secretKey;  
    $key = $secretKey . $merchantId; 

    if (verifychecksum_eFromStr(json_encode($data_repsonse), $key, $checksum_response) === "TRUE") { 
        //You can further check response code and transaction status variables in $_POST to verify transaction is success or failed.
     echo 'Checksum TRUE'; 
    }else{
        //The POST response has not come from Sadad. If you're sure it has come from Sadad, check you've passed correct secret key and merchant ID above.
     echo 'Checksum False'; 
    }

?〉

yqkkidmi

yqkkidmi1#

参考支付网关文档

monwx1rj

monwx1rj2#

它可能是从服务器端发出的,因为它以html格式给出响应,服务器无法处理json解析方法。

相关问题