-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
88 lines (84 loc) · 3.42 KB
/
atom.xml
File metadata and controls
88 lines (84 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://xfuncoding.github.io/</id>
<title>xfuncoding</title>
<updated>2020-11-24T07:10:02.880Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="http://xfuncoding.github.io/"/>
<link rel="self" href="http://xfuncoding.github.io/atom.xml"/>
<subtitle>技术实践之路</subtitle>
<logo>http://xfuncoding.github.io/images/avatar.png</logo>
<icon>http://xfuncoding.github.io/favicon.ico</icon>
<rights>All rights reserved 2020, xfuncoding</rights>
<entry>
<title type="html"><![CDATA[在Laravel中使用Yar]]></title>
<id>http://xfuncoding.github.io/post/zai-laravel-zhong-shi-yong-yar/</id>
<link href="http://xfuncoding.github.io/post/zai-laravel-zhong-shi-yong-yar/">
</link>
<updated>2020-04-28T09:21:20.000Z</updated>
<content type="html"><![CDATA[<h3 id="安装扩展包">安装扩展包</h3>
<p><strong>https://pecl.php.net/package/yar/2.0.7/windows</strong></p>
<p>1.找到php对应的版本下的扩展<br>
2.将扩展放到php下的ext目录<br>
3.修改配置文件,添加依赖 <code>extension=php_yar.dll</code></p>
<h3 id="laravel中的准备工作">laravel中的准备工作</h3>
<ol>
<li><code>composer require reprover/laravel-yar -vvv</code> //安装扩展包</li>
<li><code>php artisan vendor:publish --tag="laravel-yar"</code> //生成配置文件</li>
<li>将根目录下的/vendor/reprover/laravel-yar/config中的三个文件( yar.php:yar 运行时配置 yar-services.php:rpc 服务注册映射表 yar-map.php:mapName 与 接口参数对应表)复制到根目录的config目录下</li>
<li>修改服务端中间件跳过csrf验证 <code>app/Http/Middleware/VerifyCsrfToken.php 中的 except 数组中加上 protected $except = [ '/yar/*', ];</code></li>
</ol>
<h3 id="服务端代码">服务端代码</h3>
<pre><code><?php
namespace App\Services;
use App\Http\Service\Storage\ErpStorageStockService;
use Reprover\LaravelYar\YarService;
class StorageStockServices extends YarService
{
/**
* 获取库存
* @param $request
* @return mixed
*/
public static function getStorageSkuStock($request)
{
return app(ErpStorageStockService::class)->getStorageSkuStock($request['storage_id'],$request['sku']);
}
}
</code></pre>
<h3 id="客户端配置">客户端配置</h3>
<ol>
<li>在config 目录下 配置yar-service.php文件</li>
</ol>
<pre><code><?php
return [
'Example' => [
'path' => 'http://resource.test/yar/', 'services' => [
'ExampleService' => 'Example', //服务1
'Example2Service' => 'Example2', //服务2
]
],
]
</code></pre>
<ol start="2">
<li>在yar-map中配置</li>
</ol>
<pre><code>return [
'get_example' => [
'module' => 'Example',
'service' => 'ExampleService',
'method' => 'getExample',
'connect_timeout' => 1000,
'read_timeout' => 5000,
],
]
</code></pre>
<h3 id="客户端调用">客户端调用</h3>
<pre><code>$d = new \Yar_Client('http://127.0.0.1:8082/yar/StorageStockServices');
dump($d->getStorageSkuStock(["storage_id" => 17, "sku" => "LB10016-MQC5592-L"]));
</code></pre>
<p>查看地址<br>
http://127.0.0.1:8082/yar/StorageServices</p>
]]></content>
</entry>
</feed>