webman有没有微信支付宝的支付插件呀。

zhanqi123

webman有没有微信支付宝的支付插件呀。 Yansongda\Pay\Pay 这个插件可以用在webman上面吗。

4560 12 5
12个回答

nitron

可以用在webman上

  • fa1se 2022-03-11

    composer require alipaysdk/easysdk
    composer require wechatpay/wechatpay
    都是官方的
    git上也有很多组合的轮子,但是很多验证证书的时候总会出现异常(微信APIV3情况下出现问题较多)

nitron

这个Yansongda\Pay是二合一的,同时支持wechat/ali

我有个支付网关就是跑在webman和Yansongda\Pay下

  • zhanqi123 2022-03-11

    你是用Yansongda\Pay 什么版本的。 我用了这个支付插件。不能用。老是提示
    Error: Object of class GuzzleHttp\Psr7\Response could not be converted to string in \vendor\workerman\workerman\Protocols\Http.php:254

  • walkor 2022-03-11

    @nitron Yansongda\Pay 直接可用么?还是说要做一些兼容?
    之前有人写了个Yansongda\Pay文档给webman,https://www.workerman.net/doc/webman/components/pay.html ,看起来不符合webman项目,就没放出来。看下能否帮忙完善下这个文档,git地址 https://github.com/webman-php/webman-manual/blob/master/resource/doc/zh-cn/components/pay.md

  • nitron 2022-03-11

    2.10

  • nitron 2022-03-11

    @walkor 我网了我webman版本了, php版本7.4.3,workerman版本4.0.19

    你说的问题我看看,我们只是用到扫码支付,在微信小程序里扫对方出示的支付宝/微信二维码

  • walkor 2022-03-11

    没关系,能完善到什么程度就什么程度。

  • zhanqi123 2022-03-11

    我测试的是手机网站支付和APP支付。 都不行。 Yansongda\Pay插件的响应跟webman的响应不一样。所以不兼容

nitron

最新的V3版本似乎做了一些breaking change,部分依赖不再强制安装
https://pay.yansongda.cn/docs/v3/quick-start/install.html#%E5%AE%89%E8%A3%85%E6%80%BB%E7%BB%93

  • zhanqi123 2022-03-11

    我用的就是这个版本。操作都是按官网的去做。 但还是会出现我上面所说的错误! 搞的头痛。 最后还是用官方的SDK去做

  • nitron 2022-03-11

    提供下webman和workerman的版本

  • zhanqi123 2022-03-11

    "version": "v1.2.7",

nitron

主要是主动扫码,支付结果需要客户端去查询,我这个支付网关就是代替去客户查询,有结果了主动push给到客户端

  • 暂无评论
nitron

看了下相关的Issue,应该是guzzle里

(string)$res->getBody(); // 返回的是object,无法转换为string

workerman的\Protocols\Http.php line 254

return (string)$response;   // 这个response应该跟上面的$res->getBody()一样

获取相应内容换成了

(string)$res->getBody()->getContents();
  • zhanqi123 2022-03-11

    我试一试。

  • zhanqi123 2022-03-11

    试了没用。具体怎么替换呀。

  • nitron 2022-03-11

    等等 .你请求了之后不会是忘记使用getBody()了吧?

  • Tinywan 2022-03-11

    不行就去用V2,V2是没问题的

  • zhanqi123 2022-03-11

    感谢。成功了!!!$res = Pay::alipay()->web([
    'out_trade_no' => ''.time(),
    'total_amount' => '0.01',
    'subject' => 'yansongda测试',
    ]);

       return $res->getBody()->getContents();
  • zhanqi123 2022-03-11

    这样就可以了

  • Tinywan 2022-03-11

    哪里的问题,贴出来哦!

  • zhanqi123 2022-03-11

    Pay::config($this->config);
    Pay::set(ParserInterface::class, ArrayParser::class);
    $res = Pay::alipay()->wap([
    'out_trade_no' => ''.time(),
    'total_amount' => '0.01',
    'subject' => 'yansongda测试',
    ]);

       return $res->getBody()->getContents();           要支付的接口中 直接return $res->getBody()->getContents(); 就行了,就可以发起调起了
  • nitron 2022-03-11

    @zhang123 能不能帮我试下这个可不可行,就是把你上面的

    return $res->getBody()->getContents();

    改成

    $response = (string)$res->getBody();
    return $response;

    谢谢

  • zhanqi123 2022-03-11

    也是可以的,大神

nitron

@walkor @Tinyman @zhang123
我看了下workerman和guzzle关于Psr7/MessageTrait的实现代码
workerman内getBody只是简单的用

$this->stream = stream_for('');

guzzle的getBody内用的是自己实现的stream_for, 当对象实现to_string()时,会自动调用,以下是具体代码,

if (is_scalar($resource)) {
            $stream = self::tryFopen('php://temp', 'r+');
            if ($resource !== '') {
                fwrite($stream, (string) $resource);
                fseek($stream, 0);
            }
            return new Stream($stream, $options);
        }

        switch (gettype($resource)) {
            case 'resource':
                /*
                 * The 'php://input' is a special stream with quirks and inconsistencies.
                 * We avoid using that stream by reading it into php://temp
                 */

                /** @var resource $resource */
                if ((\stream_get_meta_data($resource)['uri'] ?? '') === 'php://input') {
                    $stream = self::tryFopen('php://temp', 'w+');
                    fwrite($stream, stream_get_contents($resource));
                    fseek($stream, 0);
                    $resource = $stream;
                }
                return new Stream($resource, $options);
            case 'object':
                /** @var object $resource */
                if ($resource instanceof StreamInterface) {
                    return $resource;
                } elseif ($resource instanceof \Iterator) {
                    return new PumpStream(function () use ($resource) {
                        if (!$resource->valid()) {
                            return false;
                        }
                        $result = $resource->current();
                        $resource->next();
                        return $result;
                    }, $options);
                } elseif (method_exists($resource, '__toString')) {
                    return self::streamFor((string) $resource, $options);
                }
                break;
            case 'NULL':
                return new Stream(self::tryFopen('php://temp', 'r+'), $options);
        }

        if (is_callable($resource)) {
            return new PumpStream($resource, $options);
        }

        throw new \InvalidArgumentException('Invalid resource type: ' . gettype($resource));
liziyu
  • 暂无评论
Tinywan

@zhanqi123 你要发红包了,整个流程给你写在这里了

完整异步回调代码


use support\Log;
use support\Request;
use support\Response;
use Webman\Config;
use Yansongda\Pay\Pay;

Log::info('『支付宝』异步通知 '.json_encode($request->post()));

$config = Config::get('payment');
Pay::config($config);
$result = Pay::alipay()->callback($request->post());

Log::info('『支付宝』接收支付宝回调: '.json_encode($result));
Log::info('『支付宝』确认回调: '.json_encode(Pay::alipay()->success()->getBody()->getContents()));

return new Response(200, [], 'success');

注意:不能使用return Pay::alipay()->success();响应支付宝,会出现中间件问题

[2022-03-11 18:01:03] default.ERROR: Return value of app\middleware\ActionHookMiddleware::process() must be an instance of Webman\Http\Response, instance of GuzzleHttp\Psr7\Response returned {"exception":"TypeError: Return value of app\\middleware\\ActionHookMiddleware::process() must be an instance of Webman\\Http\\Response, instance of GuzzleHttp\\Psr7\\Response returned in /var/www/webman.tinywan.cn/app/middleware/ActionHookMiddleware.php:48
Stack trace:

所以响应支付宝需要使用webman的响应类 support\Response;

完整异步回调日志

[2022-03-11 18:04:23] default.INFO: 『支付宝』异步通知 {"gmt_create":"2022-03-11 18:03:58","charset":"utf-8","seller_email":"knchye4942@sandbox.com","subject":"webman test","sign":"Pmzp0gaMTN5TTh1Vd25T3FeXF7stW567MeXdI74CHuuCt4ijPAjqdVracal0BXRXHDoXnD1WKOZmePsrf5eVtS9hpc0JOxmDWyYYD2xO7ZmQlK9ubensBuAGucFj63Sk7TrGPi1siYAuncVN\/6K4sxYOSOmtVEr6oBZzcxicpTfqznJ9q4ZqAyraxb2Wj3mkO8K3sqiJSEQPJG1xW89fsxy8S9DT8dGs4YJJ4YlSXz5j4yp3qFaEcMa0DuZQzGNDURKyO58F7WJ6vQGnNXTxXkxgn5IlBfZY8+6RLtejBgTEMMxCtpuIfYQ43zD4dX7vF2OZUjLnCTRxUW6udfrlvA==","buyer_id":"2088102169214338","invoice_amount":"8888.88","notify_id":"2022031100222180407014330519056694","fund_bill_list":"[{\"amount\":\"8888.88\",\"fundChannel\":\"ALIPAYACCOUNT\"}]","notify_type":"trade_status_sync","trade_status":"TRADE_SUCCESS","receipt_amount":"8888.88","buyer_pay_amount":"8888.88","app_id":"2016090900470841","sign_type":"RSA2","seller_id":"2088102174818255","gmt_payment":"2022-03-11 18:04:06","notify_time":"2022-03-11 18:04:07","version":"1.0","out_trade_no":"1646993042","total_amount":"8888.88","trade_no":"2022031122001414330501783573","auth_app_id":"2016090900470841","buyer_logon_id":"cus***@sandbox.com","point_amount":"0.00"} [] []
[2022-03-11 18:04:23] default.INFO: 『支付宝』接收支付宝回调: {"gmt_create":"2022-03-11 18:03:58","charset":"utf-8","seller_email":"knchye4942@sandbox.com","subject":"webman test","buyer_id":"2088102169214338","invoice_amount":"8888.88","notify_id":"2022031100222180407014330519056694","fund_bill_list":"[{\"amount\":\"8888.88\",\"fundChannel\":\"ALIPAYACCOUNT\"}]","notify_type":"trade_status_sync","trade_status":"TRADE_SUCCESS","receipt_amount":"8888.88","buyer_pay_amount":"8888.88","app_id":"2016090900470841","seller_id":"2088102174818255","gmt_payment":"2022-03-11 18:04:06","notify_time":"2022-03-11 18:04:07","version":"1.0","out_trade_no":"1646993042","total_amount":"8888.88","trade_no":"2022031122001414330501783573","auth_app_id":"2016090900470841","buyer_logon_id":"cus***@sandbox.com","point_amount":"0.00"} [] []
[2022-03-11 18:04:23] default.INFO: 『支付宝』确认回调: "success" [] []
  • nitron 2022-03-11

    @Tinywan 有没有我一份[doge]

  • Tinywan 2022-03-11

    必须的5:5分啊! 为了解决这个问题,亲自安装跑了一把,总算webman下成功了

walkor 打赏

@Tinywan 提交了一份支付相关的文档,欢迎参考

https://www.workerman.net/doc/webman/components/payment.html

如果你在webman使用过其它支付组件,欢迎提交文档到 https://github.com/walkor/webman-manual ,方便更多人使用

liziyu

微信支付,有大佬测试过的吗?

  • nitron 2022-03-23

    这个同时支持微信和支付宝

864328615

Pay::config($this->config);
$notify = $request->all();
$result = Pay::wechat()->callback($notify);
yansongda v3 异步回掉 写法 测试正确

年代过于久远,无法发表回答
×
🔝