为什么 Ipaymu API post 响应总是 401?

问题描述

我有一个基于 Flutter 的应用程序,我想将它与支付网关集成(在本例中为 https://ipaymu.com/)。

就我而言,我希望我的应用程序在付款时重定向到 ipaymu 页面。正如文档所说,我尝试将 POST 请求发送到 https://sandBox.ipaymu.com/api/v2/payment。但我总是收到 401 错误响应。

我的分析是,我在POST请求头中传入的签名是错误的。但是我无法进行详细分析,因为我没有看到它发生的特定错误。我的猜测是在 HMAC.SHA256 中。

这是我的完整代码

  final va = "MYVA";
  final requestBody = <String,String>{
    'account': va,'product[]': "MY PRODUCT",'qty[]': "1",'price[]': "2000",'returnUrl': "myUri",'cancelUrl': "myUri",'notifyUrl': "myUri",};
  final apikey = "myAPI";

  final sha256Body = sha256
      .convert(utf8.encode(jsonEncode(requestBody)))
      .toString()
      .toLowerCase();
  final signature = "POST:$va:$sha256Body:$apikey";

  var finalSignature = Hmac(sha256,latin1.encode(apikey))
      .convert(latin1.encode(jsonEncode(signature)))
      .toString();

  var headers = <String,String>{
    'Content-Type': 'application/json','signature': finalSignature,'va': va,'timestamp': "mytimestamp"
  };
  var request = MultipartRequest(
      'POST',Uri.parse('https://sandBox.ipaymu.com/api/v2/payment'));
  request.fields.addAll(requestBody);
  request.headers.addAll(headers);

  StreamedResponse response = await request.send();

API 文档为 here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)