alipay-global-sdk-php icon indicating copy to clipboard operation
alipay-global-sdk-php copied to clipboard

好像不兼容webman之类的常驻内存的框架

Open xiaoshuai666 opened this issue 1 year ago • 7 comments

好像不兼容webman之类的常驻内存的框架

xiaoshuai666 avatar Aug 25 '22 11:08 xiaoshuai666

感谢反馈,我在 Webman 中测试了现金支付,可以正常返回回调地址,如图所示: image SDK 本身是兼容 Webman 的,但是示例 https://github.com/mantoufan/alipay-global-sdk-php/commit/0df0a98c7319e4707736c3a6f018989f3c4c40db 不能在 Webman 中运行,因为缺少所需的 $_SERVER['HTTP_HOST'] 等 我更新了 getCurrentUrl() 方法:

function getCurrentUrl()
{
    if ($opt && isset($opt['webman']) && isset($opt['webman']['request'])) {
        $request = $opt['webman']['request'];
        return 'http' . ($request->getLocalPort() === 443 ? 's' : '') . ':' . $request->fullUrl();
    }
}

在 Webman 下,它可以像这样使用:

namespace app\controller;
use support\Request;
class Index
{
    public function index(Request $request)
    {
        $currentUrl = getCurrentUrl(array(
           'webman' => array('request' => $request)
       ));
       // Then new \Mantoufan\AliPayGlobal ……
    }
}

mantoufan avatar Aug 25 '22 16:08 mantoufan

感谢回答,在支付这里是没问题的,支付成功后,异步回调里因为大量使用了$_SERVER,所以导致抛出异常,我现在是直接使用跳过方法直接使用SignatureTool:verify进行验证的,如果要是用插件里集成的$alipayGlobal->getNotify()该如何进行兼容呢?

xiaoshuai666 avatar Aug 25 '22 16:08 xiaoshuai666

Hi, 我们更改了 0.0.3 版便于您直接传参:

composer remove mantoufan/alipay-global-sdk-php // 先移除
composer require mantoufan/alipay-global-sdk-php // 再重新安装
  1. $alipayGlobal->getNotify()时传入参数,值调用 Webman 的 $request 的方法
  2. getNotifyResponseWithRSA(),分别得到 headersbody
  3. 用 Webman 的 response 方法发送响应
$notify = $alipayGlobal->getNotify(array(
    'httpMethod' => $request->method(),
    'path' => $request->uri(),
    'clientId' => $request->header('client-id'),
    'rsqTime' => $request->header('request-time'),
    'rsqBody' => $request->rawBody(),
    'signature' => $request->header('signature')
)); 
$notifyResponseWithRSA =  $notify->getNotifyResponseWithRSA();
response($notifyResponseWithRSA['body'], 200, $notifyResponseWithRSA['headers']);

mantoufan avatar Aug 26 '22 12:08 mantoufan

好的,感谢

xiaoshuai666 avatar Aug 26 '22 13:08 xiaoshuai666

Hi, 您可以在调用 getNotify 时传入参数,示例已更新到上面,您可以试试,任何情况随时联系

mantoufan avatar Aug 26 '22 15:08 mantoufan

问题完美解决,感谢作者的付出,点赞! 另外提个不是问题的问题,根据手册上显示,异步通知最后响应支付宝的时候是不需要签名的,文档截图如下 image 另外建议如果可以把查询支付状态和取消支付这两个比较常用的接口一起集成上,就非常完美了

xiaoshuai666 avatar Aug 27 '22 03:08 xiaoshuai666

问题完美解决,感谢作者的付出,点赞! 另外提个不是问题的问题,根据手册上显示,异步通知最后响应支付宝的时候是不需要签名的,文档截图如下 image 另外建议如果可以把查询支付状态和取消支付这两个比较常用的接口一起集成上,就非常完美了

xiaoshuai666 avatar Aug 27 '22 03:08 xiaoshuai666