think.studio/laravel-myriad-soap

与 Myriad 5.1 的非官方Web集成

1.4.0 2023-07-11 05:43 UTC

This package is auto-updated.

Last update: 2024-09-11 08:17:06 UTC


README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

与 Myriad 5.1 的非官方Web集成

安装

您可以通过 composer 安装此包

composer require think.studio/laravel-myriad-soap

php artisan vendor:publish --provider="MyriadSoap\ServiceProvider" --tag="config"

使用

通过外观直接调用

$result = MyriadSoap::SOAP_getContactCommunications(['Contact_ID' => 1234]);
/*
    [
     "ContactCommunication" => [
       "123456;12;01234 567 890;Yes",
       "123457;14;me@test.co.uk;No",
     ],
    ]
*/

默认情况下,Myriad 列表响应包含意外的字符串列表响应,因此将非常有用的助手

MyriadSoap::SOAP_getContactCommunications_List(['Contact_ID' => 1234], 3, 'ContactCommunication' /* Optional, as appropriate key, app will try guess itself */);

或将响应转换为集合

MyriadSoap::SOAP_getContactCommunications_Collection(['Contact_ID' => 1234], [
        'ContactCommunication_ID' => fn($i) => (int) $i,
        'DespatchType_ID' => fn($i) => (int) $i,
        'ContactCommunication',
        'PrimaryUse'              => fn($i) => $i == 'Yes',
    ], 'ContactCommunication' /* Optional, as appropriate key, app will try guess itself */);

要获取非字符串列表,请使用 AssocCollection 调用

MyriadSoap::SOAP_getOrderPackageTypes_AssocCollection([], [
            'OrderPackageType_ID' => fn($i) => (int) tap($i, fn() => throw_if(! is_numeric($i), UnexpectedTypeException::class)),
            'OrderPackageType' => fn($i) => (string) $i,
            'OrderPackageCategory',
        ], 'OrderPackageType' /* Optional, as appropriate key, app will try guess itself */);

使用允许您包装自己的业务逻辑的功能集(每个类都应 extends FunctionsSet

use MyriadSoap\Endpoints\FunctionsSet;

class MyContactFunctions extends FunctionsSet {

    public function getContactCommunications( int $customerNumber ) {
        return $this->api->call(
            'SOAP_getContactCommunications',
            [
                'Contact_ID' => $customerNumber,
            ]
        );
    }
}

$result =  MyriadSoap::functionsSet(MyContactFunctions::class)->getContactCommunications(1234);

鸣谢

  • Think Studio