我在使用whmcs时遇到了一个有趣的挑战。
我正在编写一个插件,将支付网关集成到whmcs安装中。
我已完成插件的第一部分,即添加付款按钮,触发付款网关模式并方便付款。
付款成功或失败后,支付网关会使用看起来像这样的get参数重定向回whmcs回调网址。
https://www.domainname.com/whmcs/modules/gateways/callback/gateway.php?resp=urlencoded-json-string
接下来要做的就是收集$ _GET ['resp']参数并对其进行解码
<?php
// Require libraries needed for gateway module functions.
require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/../../../includes/gatewayfunctions.php';
require_once __DIR__ . '/../../../includes/invoicefunctions.php';
$response = $_GET['resp'];
$response = json_decode($response);
// and access the values like
$response->tx->amount //10.00
然而,Json_decode失败并返回null,就像json格式不正确一样。
经过进一步调查。
我意识到,如果在非whmcs安装上测试这个精确的url字符串,json_decode工作正常,我可以作为对象或关联数组访问数据。
当我从网关回调文件中删除下面的行时。它工作正常。似乎是whmcs应用程序正在搞乱json函数。
// Require libraries needed for gateway module functions.
require_once __DIR__ . '/../../../init.php';
但支付网关回调无法使用必要的标头,尤其是init.php文件。
我如何处理这种情况并超越它。
感谢。
答案 0 :(得分:0)
好的,我想通了@GerardVanHelden的建议,WHMCS可能会弄乱$ _GET值。
所以我只是在require_once语句之前收集$ _GET值。 和json_decode正常工作。
干杯。