我该如何将JSON阵列张开

发布于 2025-02-10 07:08:21 字数 5467 浏览 0 评论 0原文

我正在尝试使用带有格式数组的API将数据发布到服务器中,但是我得到了一个错误:

E/flutter (20862): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error: 
E/flutter (20862):  CERTIFICATE_VERIFY_FAILED: certificate has expired(handshake.cc:393))

在Postman中,它运行良好并给出了200个,但结果是错误的:

{
    "success": false,
    "statuscode": 101,
    "message": "Unauthorized"
}

因为我没有生成生成哈希密钥 但是我的代码中的proplam并没有给我任何结果。请求失败,因为 当我发布
时的身体错误 此链接邮递员集合: https://wwwwwww.getpostman.com/collectman.com/collections/52c6c6cbb1cd1cd1671681 b

. /code>格式我拥有的:

[
  {
    "cc_holder_name": "John Dao",
    "cc_no": "4508034508034509",
    "expiry_month": 12,
    "expiry_year": 2026,
    "cvv": 543,
    "currency_code": "TRY",
    "total": 458,
    "merchant_key":r"$2y$10$HmRgYosneqcwHj.UH7upGuyCZqpQ1ITgSMj9Vvxn.t6f.Vdf2SQFO",
    "items": "[\n  {\"name\":\"pr001\",\"price\":\"2.30\",\"quantity\":1,\"description\":\"pr001\"},\n  {\"name\":\"pr001\",\"price\":\"2.70\",\"quantity\":1,\"description\":\"pr001\"},\n  {\"name\":\"pr001\",\"price\":\"5.00\",\"quantity\":2,\"description\":\"pr001\"}\n]\n",
    "cancel_url": "string",
    "return_url": "string",
    "hash_key": "string",
    "order_type": 0,
  }
]

这是我的代码

class SiPayModel {
  String? ccHolderName;
  String? ccNo;
  int? expiryMonth;
  int? expiryYear;
  int? cvv;
  String? currencyCode;
  int? installmentsNumber;
  int? invoiceId;
  String? invoiceDescription;
  String? name;
  String? surname;
  int? total;
  String? merchantKey;
  String? items;
  String? cancelUrl;
  String? returnUrl;
  String? hashKey;
  int? orderType;

  SiPayModel(
      { this.ccHolderName,
        this.ccNo,
        this.expiryMonth,
        this.expiryYear,
        this.cvv,
        this.currencyCode,
        this.installmentsNumber,
        this.invoiceId,
        this.invoiceDescription,
        this.name,
        this.surname,
        this.total,
        this.merchantKey,
        this.items,
        this.cancelUrl,
        this.returnUrl,
        this.hashKey,
        this.orderType,
      });

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['cc_holder_name'] = this.ccHolderName;
    data['cc_no'] = this.ccNo;
    data['expiry_month'] = this.expiryMonth;
    data['expiry_year'] = this.expiryYear;
    data['cvv'] = this.cvv;
    data['currency_code'] = this.currencyCode;
    data['installments_number'] = this.installmentsNumber;
    data['invoice_id'] = this.invoiceId;
    data['invoice_description'] = this.invoiceDescription;
    data['name'] = this.name;
    data['surname'] = this.surname;
    data['total'] = this.total;
    data['merchant_key'] = this.merchantKey;
    data['items'] = this.items;
    data['cancel_url'] = this.cancelUrl;
    data['return_url'] = this.returnUrl;
    data['hash_key'] = this.hashKey;
    data['order_type'] = this.orderType;

    return data;
  }
}

,而不是我试图将数据发布到服务器

import 'dart:convert' as convert;
import 'package:http/http.dart' as http;

import '../model/sipayjson.dart';

class SiPay {

  static const testUrl = "https://provisioning.sipay.com.tr/ccpayment/api/paySmart2D";
  static const liveUrl = "https://app.sipay.com.tr/ccpayment/api/paySmart2D";
  static const sKey = "b46a67571aa1e7ef566f1712a";
  static const pKey = "6d4a7e9374a7315b0b9";
  static const merchantKey =
      "${2}y${10}HmRgYosneqcwHj.UH7upGuyCZqpQ1ITgSMj9Vvxn.t6f.Vdf2SQFO";

  Map<String, String> header = {
    "Content type": "application/json",
    "Authorization": " Bearer",
    "Accept": "application/json",
  };

 // Map<String,dynamic>body =  {
 //  "cc_holder_name": "John Dao",
 //  "cc_no": "4508034508034509",
 //  "expiry_month": 12,
 //  "expiry_year": 2026,
 //  "cvv": 543,
 //  "currency_code": "TRY",
 //  "installments_number": 1,
 //  "invoice_id": 5874544,
 //  "invoice_description": "5974544 Ödemesi",
 //  "name": "John",
 //  "surname": "Dao",
 //  "total": 458,
 //  "merchant_key": merchantKey,
 //  "items": "[{}]",
 //  "cancel_url": "string",
 //  "return_url": "string",
 //  "hash_key": "string",
 //  "order_type": 0,
 //  };

  Future<void> doPayment() async {
    SiPayModel  siPayModel=
    SiPayModel(
        ccHolderName: "John Dao",
        ccNo: "4508034508034509",
        expiryMonth: 12,
        expiryYear: 2026,
        cvv: 543,
        currencyCode: "TRY",
        installmentsNumber: 1,
        invoiceId: 5874544,
        invoiceDescription: "5974544 Ödemesi",
        name: "John",
        surname: "Dao",
        total: 458,
        merchantKey: "54864646fdhdfasfas",
        items: "[{\"name\":\"pr001\",\"price\":\"2.30\"}]",
        cancelUrl: "",
        returnUrl: "",
        hashKey: "",
        orderType: 0
    );
   var res = await http.post(
        Uri.parse(testUrl),
        headers: header,
        body:convert.jsonEncode(siPayModel.toJson())
       // I did like this also dosent work
       // body:siPayModel.toJson()
    );
    if (res.statusCode == 200) {
      print(res.statusCode);
      print(res.body);
    } else {
      print(res.statusCode);
      throw Exception("Payment error");
    }
  }
}

I am trying to post data to server using API with format Array in flutter but i got this error :

E/flutter (20862): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error: 
E/flutter (20862):  CERTIFICATE_VERIFY_FAILED: certificate has expired(handshake.cc:393))

in postman it is working good and gave 200 but result it will be false :

{
    "success": false,
    "statuscode": 101,
    "message": "Unauthorized"
}

because i didn't generate hash key
but proplam in my code didn't gave me any result. request failed because
mistake in body when i posted
this link postman collection :
https://www.getpostman.com/collections/52c6cb1cd168f9719b12

this is json format what I have:

[
  {
    "cc_holder_name": "John Dao",
    "cc_no": "4508034508034509",
    "expiry_month": 12,
    "expiry_year": 2026,
    "cvv": 543,
    "currency_code": "TRY",
    "total": 458,
    "merchant_key":r"$2y$10$HmRgYosneqcwHj.UH7upGuyCZqpQ1ITgSMj9Vvxn.t6f.Vdf2SQFO",
    "items": "[\n  {\"name\":\"pr001\",\"price\":\"2.30\",\"quantity\":1,\"description\":\"pr001\"},\n  {\"name\":\"pr001\",\"price\":\"2.70\",\"quantity\":1,\"description\":\"pr001\"},\n  {\"name\":\"pr001\",\"price\":\"5.00\",\"quantity\":2,\"description\":\"pr001\"}\n]\n",
    "cancel_url": "string",
    "return_url": "string",
    "hash_key": "string",
    "order_type": 0,
  }
]

this is my code

class SiPayModel {
  String? ccHolderName;
  String? ccNo;
  int? expiryMonth;
  int? expiryYear;
  int? cvv;
  String? currencyCode;
  int? installmentsNumber;
  int? invoiceId;
  String? invoiceDescription;
  String? name;
  String? surname;
  int? total;
  String? merchantKey;
  String? items;
  String? cancelUrl;
  String? returnUrl;
  String? hashKey;
  int? orderType;

  SiPayModel(
      { this.ccHolderName,
        this.ccNo,
        this.expiryMonth,
        this.expiryYear,
        this.cvv,
        this.currencyCode,
        this.installmentsNumber,
        this.invoiceId,
        this.invoiceDescription,
        this.name,
        this.surname,
        this.total,
        this.merchantKey,
        this.items,
        this.cancelUrl,
        this.returnUrl,
        this.hashKey,
        this.orderType,
      });

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['cc_holder_name'] = this.ccHolderName;
    data['cc_no'] = this.ccNo;
    data['expiry_month'] = this.expiryMonth;
    data['expiry_year'] = this.expiryYear;
    data['cvv'] = this.cvv;
    data['currency_code'] = this.currencyCode;
    data['installments_number'] = this.installmentsNumber;
    data['invoice_id'] = this.invoiceId;
    data['invoice_description'] = this.invoiceDescription;
    data['name'] = this.name;
    data['surname'] = this.surname;
    data['total'] = this.total;
    data['merchant_key'] = this.merchantKey;
    data['items'] = this.items;
    data['cancel_url'] = this.cancelUrl;
    data['return_url'] = this.returnUrl;
    data['hash_key'] = this.hashKey;
    data['order_type'] = this.orderType;

    return data;
  }
}

than here I was trying to post my data to server

import 'dart:convert' as convert;
import 'package:http/http.dart' as http;

import '../model/sipayjson.dart';

class SiPay {

  static const testUrl = "https://provisioning.sipay.com.tr/ccpayment/api/paySmart2D";
  static const liveUrl = "https://app.sipay.com.tr/ccpayment/api/paySmart2D";
  static const sKey = "b46a67571aa1e7ef566f1712a";
  static const pKey = "6d4a7e9374a7315b0b9";
  static const merchantKey =
      "${2}y${10}HmRgYosneqcwHj.UH7upGuyCZqpQ1ITgSMj9Vvxn.t6f.Vdf2SQFO";

  Map<String, String> header = {
    "Content type": "application/json",
    "Authorization": " Bearer",
    "Accept": "application/json",
  };

 // Map<String,dynamic>body =  {
 //  "cc_holder_name": "John Dao",
 //  "cc_no": "4508034508034509",
 //  "expiry_month": 12,
 //  "expiry_year": 2026,
 //  "cvv": 543,
 //  "currency_code": "TRY",
 //  "installments_number": 1,
 //  "invoice_id": 5874544,
 //  "invoice_description": "5974544 Ödemesi",
 //  "name": "John",
 //  "surname": "Dao",
 //  "total": 458,
 //  "merchant_key": merchantKey,
 //  "items": "[{}]",
 //  "cancel_url": "string",
 //  "return_url": "string",
 //  "hash_key": "string",
 //  "order_type": 0,
 //  };

  Future<void> doPayment() async {
    SiPayModel  siPayModel=
    SiPayModel(
        ccHolderName: "John Dao",
        ccNo: "4508034508034509",
        expiryMonth: 12,
        expiryYear: 2026,
        cvv: 543,
        currencyCode: "TRY",
        installmentsNumber: 1,
        invoiceId: 5874544,
        invoiceDescription: "5974544 Ödemesi",
        name: "John",
        surname: "Dao",
        total: 458,
        merchantKey: "54864646fdhdfasfas",
        items: "[{\"name\":\"pr001\",\"price\":\"2.30\"}]",
        cancelUrl: "",
        returnUrl: "",
        hashKey: "",
        orderType: 0
    );
   var res = await http.post(
        Uri.parse(testUrl),
        headers: header,
        body:convert.jsonEncode(siPayModel.toJson())
       // I did like this also dosent work
       // body:siPayModel.toJson()
    );
    if (res.statusCode == 200) {
      print(res.statusCode);
      print(res.body);
    } else {
      print(res.statusCode);
      throw Exception("Payment error");
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文