{"id":4538,"date":"2019-09-02T19:36:55","date_gmt":"2019-09-02T10:36:55","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=4538"},"modified":"2019-09-02T19:36:55","modified_gmt":"2019-09-02T10:36:55","slug":"%e3%80%90php%e3%80%91%e4%b8%96%e7%95%8c%e3%81%ae%e4%b8%bb%e8%a6%81%e9%80%9a%e8%b2%a8%e3%82%92%e6%97%a5%e6%9c%ac%e5%86%86%e3%81%ab%e5%a4%89%e6%8f%9b%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=4538","title":{"rendered":"\u3010PHP\u3011\u4e16\u754c\u306e\u4e3b\u8981\u901a\u8ca8\u3092\u65e5\u672c\u5186\u306b\u5909\u63db\u3059\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4ee5\u524d\u79c1\u306f\u30ab\u30ca\u30c0\u306e\u30d0\u30f3\u30af\u30fc\u30d0\u30fc\u306b\u7559\u5b66\u3057\u3066\u305f\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u65e5\u672c\u306b\u5e30\u3063\u3066\u304d\u3066\u304b\u3089\u3082\u3053\u3061\u3089\u3067\u306f\u58f2\u3063\u3066\u3044\u306a\u3044\u300c\u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u300d\u3084\u300c\u30ed\u30fc\u30b9\u30c8\u3057\u305f\u3072\u307e\u308f\u308a\u306e\u7a2e\u300d\u300c\u30db\u30c3\u30c8\u30c1\u30e7\u30b3\u30ec\u30fc\u30c8\u300d\u304c\u305f\u307e\u306b\u98df\u3079\u305f\u304f\u306a\u3063\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u3093\u306a\u3068\u304d\u306b\u3088\u304f\u601d\u3046\u306e\u304c\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u305d\u3046\u3044\u3048\u3070\u3001\u73fe\u5730\u306e\u901a\u8ca8\u3092\u65e5\u672c\u5186\u306b\u3059\u308b\u306e\u3063\u3066\u3081\u3093\u3069\u304f\u3055\u304b\u3063\u305f\u306a\u30fc\ud83d\ude05<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u9577\u304f\u751f\u6d3b\u3057\u3066\u3044\u308b\u3068\u3060\u3044\u305f\u3044\u9ad8\u3044\u5b89\u3044\u306f\u5206\u304b\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u304c\u3001\u884c\u3063\u3066\u3059\u3050\u3060\u3068\u3044\u3061\u3044\u3061\u982d\u306e\u4e2d\u3067\u8a08\u7b97\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3067\u3059\u3057\u3001\u306a\u306b\u3088\u308a\u82f1\u8a9e\u3067\u3057\u3083\u3079\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u304b\u3089\u982d\u306f\u3050\u3061\u3083\u3050\u3061\u3083\u306b\u306a\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3057\u305f\ud83d\udca6<\/p>\n<p>\u3068\u3044\u3046\u3053\u3067\u3001\u4eca\u56de\u306f\u305d\u3093\u306a\u7d4c\u9a13\u3082\u8e0f\u307e\u3048\u3066<code>PHP<\/code>\u3092\u4f7f\u3063\u3066\u4e16\u754c\u306e\u4e3b\u8981\u901a\u8ca8\u3092\u65e5\u672c\u5186\u306b\u8a08\u7b97\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u6700\u5f8c\u306b\u3001<code>Laravel<\/code>\u3067\u901a\u8ca8\u306e\u81ea\u52d5\u8a08\u7b97\u3059\u308bLINE\u30dc\u30c3\u30c8\u3092\u3064\u304f\u308b\u65b9\u6cd5\u3082\u7d39\u4ecb\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3405 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png\" alt=\"\" width=\"310\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png 310w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18-291x300.png 291w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/p>\n<p>\u958b\u767a\u74b0\u5883\uff1a PHP 7.2, Laravel 5.8<\/p>\n<h1>\u70ba\u66ff\u30ec\u30fc\u30c8\u306e\u60c5\u5831\u3092\u3069\u3053\u304b\u3089\u3068\u308b\u304b<\/h1>\n<p>\u3082\u3061\u308d\u3093\u70ba\u66ff\u30ec\u30fc\u30c8\u306f\u5909\u52d5\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u5e38\u306b\u65b0\u3057\u3044\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u672c\u683c\u7684\u306b\u3084\u308d\u3046\u3068\u601d\u3048\u3070\u3001\u53d6\u5f15\u6240\u304b\u3089\u767a\u884c\u3055\u308c\u308b\u30c7\u30fc\u30bf\u3092\u81ea\u524d\u3067\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u306a\u306e\u3067\u4ee5\u4e0b\u306eAPI\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002\uff08\u3068\u306f\u3044\u3063\u3066\u3082\u3001\u3053\u306eAPI\u3082\u5143\u306f\u6b27\u5dde\u4e2d\u592e\u9280\u884c\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u3068\u306e\u3053\u3068\u3067\u3059\uff09<\/p>\n<p><a href=\"https:\/\/exchangeratesapi.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Foreign exchange rates API <\/a><\/p>\n<h1>\u4e16\u754c\u306e\u4e3b\u8981\u901a\u8ca8\u3092\u5225\u306e\u901a\u8ca8\u306b\u5909\u63db\u3059\u308b\u95a2\u6570<\/h1>\n<p>\u3067\u306f\u3001<code>Foreign exchange rates API<\/code>\u3092\u4f7f\u3063\u305f\u901a\u8ca8\u5909\u63db\u306e\u95a2\u6570\u3067\u3059\u3002<\/p>\n<pre><strong>function convert_currency($amount, $from_symbol, $to_symbol, $decimal_point = 2) {<\/strong>\r\n\r\n<strong>    $converted_amount = null;<\/strong>\r\n<strong>    $url = 'https:\/\/api.exchangeratesapi.io\/latest?base='. $from_symbol;<\/strong>\r\n<strong>    $data = json_decode(file_get_contents($url), true);<\/strong>\r\n\r\n<strong>    if(isset($data['rates'][$to_symbol])) {<\/strong>\r\n\r\n<strong>        $converted_amount = round($data['rates'][$to_symbol] * $amount, $decimal_point);<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>    return $converted_amount;<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u4f7f\u3044\u65b9\u306f\u3001\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002\uff08\u3053\u306e\u4f8b\u3067\u306f\u3001100\u7c73\u30c9\u30eb\u3092\u65e5\u672c\u5186\u306b\u5909\u63db\u3057\u3001\u5c11\u6570\u7b2c\uff12\u4f4d\u307e\u3067\u6c42\u3081\u307e\u3059\uff09<\/p>\n<pre><strong>$amount = 100;          \/\/ \u91d1\u984d<\/strong>\r\n<strong>$from_symbol = 'USD';   \/\/ \u3053\u306e\u901a\u8ca8\u3092<\/strong>\r\n<strong>$to_symbol = 'JPY';     \/\/ \u3053\u306e\u901a\u8ca8\u306b\u5909\u63db<\/strong>\r\n<strong>$decimal_point = 2;     \/\/ \u5c0f\u6570\u70b9\u7b2c\uff12\u4f4d\u3067\u56db\u6368\u4e94\u5165<\/strong>\r\n<strong>echo convert_currency($amount, $from_symbol, $to_symbol, $decimal_point);<\/strong><\/pre>\n<p>\u306a\u304a\u3001\u3053\u306eAPI\u3067\u5229\u7528\u3067\u304d\u308b\u901a\u8ca8\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002\uff082019.09.02\u73fe\u5728\uff09<\/p>\n<pre>USD\uff1a \u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd\u30c9\u30eb\r\nEUR\uff1a \u30e6\u30fc\u30ed\r\nCNY\uff1a \u4eba\u6c11\u5143\r\nKRW\uff1a \u30a6\u30a9\u30f3\r\nCAD\uff1a \u30ab\u30ca\u30c0\u30fb\u30c9\u30eb\r\nAUD\uff1a \u30aa\u30fc\u30b9\u30c8\u30e9\u30ea\u30a2\u30fb\u30c9\u30eb\r\nNZD\uff1a \u30cb\u30e5\u30fc\u30b8\u30fc\u30e9\u30f3\u30c9\u30fb\u30c9\u30eb\r\nHKD\uff1a \u9999\u6e2f\u30c9\u30eb\r\nSGD\uff1a \u30b7\u30f3\u30ac\u30dd\u30fc\u30eb\u30fb\u30c9\u30eb\r\nGBP\uff1a UK\u30dd\u30f3\u30c9\r\nISK\uff1a \u30a2\u30a4\u30b9\u30e9\u30f3\u30c9\u30fb\u30af\u30ed\u30fc\u30ca\r\nPHP\uff1a \u30d5\u30a3\u30ea\u30d4\u30f3\u30fb\u30da\u30bd\r\nDKK\uff1a \u30c7\u30f3\u30de\u30fc\u30af\u30fb\u30af\u30ed\u30fc\u30cd\r\nHUF\uff1a \u30d5\u30a9\u30ea\u30f3\u30c8\r\nCZK\uff1a \u30c1\u30a7\u30b3\u30fb\u30b3\u30eb\u30ca\r\nRON\uff1a \u30eb\u30fc\u30de\u30cb\u30a2\u30fb\u30ec\u30a6\r\nSEK\uff1a \u30b9\u30a6\u30a7\u30fc\u30c7\u30f3\u30fb\u30af\u30ed\u30fc\u30ca\r\nIDR\uff1a \u30eb\u30d4\u30a2\r\nINR\uff1a \u30a4\u30f3\u30c9\u30fb\u30eb\u30d4\u30fc\r\nBRL\uff1a \u30ec\u30a2\u30eb\r\nRUB\uff1a \u30ed\u30b7\u30a2\u30fb\u30eb\u30fc\u30d6\u30eb\r\nHRK\uff1a \u30af\u30fc\u30ca\r\nTHB\uff1a \u30d0\u30fc\u30c4\r\nCHF\uff1a \u30b9\u30a4\u30b9\u30fb\u30d5\u30e9\u30f3\r\nMYR\uff1a \u30ea\u30f3\u30ae\u30c3\u30c8\r\nBGN\uff1a \u30ec\u30d5\r\nTRY\uff1a \u30c8\u30eb\u30b3\u30ea\u30e9\r\nNOK\uff1a \u30ce\u30eb\u30a6\u30a7\u30fc\u30fb\u30af\u30ed\u30fc\u30cd\r\nZAR\uff1a \u30e9\u30f3\u30c9\r\nMXN\uff1a \u30e1\u30ad\u30b7\u30b3\u30fb\u30da\u30bd\r\nILS\uff1a \u30b7\u30a7\u30b1\u30eb\r\nPLN\uff1a \u30ba\u30a6\u30a9\u30c6\u30a3<\/pre>\n<h1>\u4e16\u754c\u306e\u4e3b\u8981\u901a\u8ca8\u3092\u65e5\u672c\u5186\u306b\u5909\u63db\u3059\u308bLINE\u30dc\u30c3\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u304b\u3089<code>Laravel<\/code>\u306e\u304a\u8a71\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u5148\u307b\u3069\u306e\u901a\u8ca8\u3092\u5909\u63db\u3059\u308b\u65b9\u6cd5\u3092\u5fdc\u7528\u3057\u3066\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u5148\u306b\u8a66\u3057\u3066\u307f\u308b\u5834\u5408\u306f\u3053\u3061\u3089\u306eQR\u30b3\u30fc\u30c9\u3092\u8aad\u307f\u53d6\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3010LINE\uff1a\u65e5\u672c\u5186\u3060\u3068\u3044\u304f\u3089\uff1f\uff1f\u3011<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4541\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_1.png\" alt=\"\" width=\"187\" height=\"182\" \/><\/p>\n<h2>LINE\u5074\u306e\u4f5c\u696d<\/h2>\n<p><a href=\"https:\/\/blog.capilano-fw.com\/?p=4285\">Laravel\u3067LINE\u306b\u30c1\u30e3\u30c3\u30c8\u30dc\u30c3\u30c8\u3092\u3064\u304f\u308b\uff08QR\u30b3\u30fc\u30c9\u4f5c\u6210\uff09<\/a>\u306e<strong>\u300cLINE Messaging API\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u300d<\/strong>\u3068<strong>\u300c\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u300d<\/strong>\u3092\u53c2\u8003\u306b\u3057\u3066\u5b9f\u884c\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u57fa\u672c\u7684\u306b\u306f\u540c\u3058\u4f5c\u696d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h2>\n<p>\u307e\u305a\u306f\u30eb\u30fc\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n<code>routes\/web.php<\/code>\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>Route::post('currency-bot', 'CurrencyBotController@webhook');<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001LINE\u304b\u3089\u306e\u9001\u4fe1\u306f<code>CSRF<\/code>\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u304c\u9069\u7528\u3055\u308c\u306a\u3044\u3088\u3046\u306b<code>app\/Http\/Middleware\/VerifyCsrfToken.php<\/code>\u3092\u958b\u3044\u3066\u4e0a\u3067\u6307\u5b9a\u3057\u305fURL\u3092<code>$except<\/code>\u306b\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>    protected $except = [\r\n        <strong>'currency-bot',<\/strong>\r\n    ];<\/pre>\n<h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h2>\n<p>\u7d9a\u3044\u3066\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308a\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:controller CurrencyBotController<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>app\/Http\/Controllers\/CurrencyBotController.php<\/code>\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Carbon\\Carbon;\r\nuse Illuminate\\Http\\Request;\r\nuse LINE\\LINEBot;\r\nuse LINE\\LINEBot\\Event\\MessageEvent;\r\nuse LINE\\LINEBot\\Event\\MessageEvent\\TextMessage;\r\nuse LINE\\LINEBot\\HTTPClient\\CurlHTTPClient;\r\n\r\nclass CurrencyBotController extends Controller\r\n{\r\n    private $_currency_symbols = [\r\n        'USD' =&gt; '\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd\u30c9\u30eb',\r\n        'EUR' =&gt; '\u30e6\u30fc\u30ed',\r\n        'CNY' =&gt; '\u4eba\u6c11\u5143',\r\n        'KRW' =&gt; '\u30a6\u30a9\u30f3',\r\n        'CAD' =&gt; '\u30ab\u30ca\u30c0\u30fb\u30c9\u30eb',\r\n        'AUD' =&gt; '\u30aa\u30fc\u30b9\u30c8\u30e9\u30ea\u30a2\u30fb\u30c9\u30eb',\r\n        'NZD' =&gt; '\u30cb\u30e5\u30fc\u30b8\u30fc\u30e9\u30f3\u30c9\u30fb\u30c9\u30eb',\r\n        'HKD' =&gt; '\u9999\u6e2f\u30c9\u30eb',\r\n        'SGD' =&gt; '\u30b7\u30f3\u30ac\u30dd\u30fc\u30eb\u30fb\u30c9\u30eb',\r\n        'GBP' =&gt; 'UK\u30dd\u30f3\u30c9',\r\n        'ISK' =&gt; '\u30a2\u30a4\u30b9\u30e9\u30f3\u30c9\u30fb\u30af\u30ed\u30fc\u30ca',\r\n        'PHP' =&gt; '\u30d5\u30a3\u30ea\u30d4\u30f3\u30fb\u30da\u30bd',\r\n        'DKK' =&gt; '\u30c7\u30f3\u30de\u30fc\u30af\u30fb\u30af\u30ed\u30fc\u30cd',\r\n        'HUF' =&gt; '\u30d5\u30a9\u30ea\u30f3\u30c8',\r\n        'CZK' =&gt; '\u30c1\u30a7\u30b3\u30fb\u30b3\u30eb\u30ca',\r\n        'RON' =&gt; '\u30eb\u30fc\u30de\u30cb\u30a2\u30fb\u30ec\u30a6',\r\n        'SEK' =&gt; '\u30b9\u30a6\u30a7\u30fc\u30c7\u30f3\u30fb\u30af\u30ed\u30fc\u30ca',\r\n        'IDR' =&gt; '\u30eb\u30d4\u30a2',\r\n        'INR' =&gt; '\u30a4\u30f3\u30c9\u30fb\u30eb\u30d4\u30fc',\r\n        'BRL' =&gt; '\u30ec\u30a2\u30eb',\r\n        'RUB' =&gt; '\u30ed\u30b7\u30a2\u30fb\u30eb\u30fc\u30d6\u30eb',\r\n        'HRK' =&gt; '\u30af\u30fc\u30ca',\r\n        'THB' =&gt; '\u30d0\u30fc\u30c4',\r\n        'CHF' =&gt; '\u30b9\u30a4\u30b9\u30fb\u30d5\u30e9\u30f3',\r\n        'MYR' =&gt; '\u30ea\u30f3\u30ae\u30c3\u30c8',\r\n        'BGN' =&gt; '\u30ec\u30d5',\r\n        'TRY' =&gt; '\u30c8\u30eb\u30b3\u30ea\u30e9',\r\n        'NOK' =&gt; '\u30ce\u30eb\u30a6\u30a7\u30fc\u30fb\u30af\u30ed\u30fc\u30cd',\r\n        'ZAR' =&gt; '\u30e9\u30f3\u30c9',\r\n        'MXN' =&gt; '\u30e1\u30ad\u30b7\u30b3\u30fb\u30da\u30bd',\r\n        'ILS' =&gt; '\u30b7\u30a7\u30b1\u30eb',\r\n        'PLN' =&gt; '\u30ba\u30a6\u30a9\u30c6\u30a3'\r\n    ];\r\n\r\n    public function webhook(Request $request) {\r\n\r\n        <strong>$channel_secret = '\uff08\u3053\u3053\u306bLINE\u306e\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u9375\uff09';\r\n        $access_token = '\uff08\u3053\u3053\u306bLINE\u306e\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\uff09';<\/strong>\r\n        $request_body = $request-&gt;getContent();\r\n        $hash = hash_hmac('sha256', $request_body, $channel_secret, true);\r\n        $signature = base64_encode($hash);\r\n\r\n        if($signature === $request-&gt;header('X-Line-Signature')) {   \/\/ LINE\u304b\u3089\u306e\u9001\u4fe1\u3092\u691c\u8a3c\r\n\r\n            $client = new CurlHTTPClient($access_token);\r\n            $bot = new LINEBot($client, ['channelSecret' =&gt; $channel_secret]);\r\n\r\n            try {\r\n\r\n                $events = $bot-&gt;parseEventRequest($request_body, $signature);\r\n\r\n                foreach ($events as $event) {\r\n\r\n                    if($event instanceof MessageEvent &amp;&amp; $event instanceof TextMessage) {   \/\/ \u30c6\u30ad\u30b9\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5834\u5408\r\n\r\n                        $text = mb_convert_kana($event-&gt;getText(), 'a');    \/\/ LINE\u3067\u9001\u4fe1\u3055\u308c\u305f\u30c6\u30ad\u30b9\u30c8\r\n                        $reply_token = $event-&gt;getReplyToken();     \/\/ \u8fd4\u4fe1\u7528\u30c8\u30fc\u30af\u30f3\r\n                        $pattern = '|([0-9\\.]+) ?([a-zA-Z]{3})|';\r\n\r\n                        if(preg_match($pattern, $text, $matches)) {\r\n\r\n                            $amount = $matches[1];\r\n                            $symbol = strtoupper($matches[2]);\r\n\r\n                            if (isset($this-&gt;_currency_symbols[$symbol])) {\r\n\r\n                                $currency_name = $this-&gt;_currency_symbols[$symbol];\r\n                                $jpy_content = <strong>$this-&gt;jpyContent($amount, $symbol);<\/strong>\r\n\r\n                                if(!empty($jpy_content)) {\r\n\r\n                                    $replying_text = number_format($amount) .' '. $currency_name .\"\u306f\u3001\\n\\n\".\r\n                                        $jpy_content;\r\n\r\n                                }\r\n\r\n                            }\r\n\r\n                        }\r\n\r\n                        if(empty($replying_text)) {\r\n\r\n                            $replying_text = \"\u91d1\u984d\u306e\u5f62\u5f0f\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002\".\r\n                                $this-&gt;emoji('100094') .\r\n                                $this-&gt;emoji('100029') .\"\\n\\n\".\r\n                                \"\u3010\u4f8b\u3011100usd\\n\uff08100\u30c9\u30eb \u2192 \u65e5\u672c\u5186\u3067\u3044\u304f\u3089\uff1f\uff09\\n\\n\".\r\n                                \"\u306a\u304a\u3001\u5229\u7528\u3067\u304d\u308b\u901a\u8ca8\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\uff08\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306f\u3069\u3061\u3089\u3067\u3082OK\uff09\". $this-&gt;emoji('10002D') .\"\\n\\n\".\r\n                                $this-&gt;currencySymbolContent();\r\n\r\n                        }\r\n\r\n                        $bot-&gt;replyText($reply_token, $replying_text);    \/\/ \u8fd4\u4fe1\r\n                        break;\r\n\r\n                    }\r\n\r\n                }\r\n\r\n            } catch (\\Exception $e) {}\r\n\r\n        }\r\n\r\n    }\r\n\r\n    <strong>private function jpyContent($amount, $symbol) {<\/strong>\r\n\r\n<strong>        $content = '';<\/strong>\r\n<strong>        $url = 'https:\/\/api.exchangeratesapi.io\/latest?base='. $symbol;<\/strong>\r\n<strong>        $data = json_decode(file_get_contents($url), true);<\/strong>\r\n\r\n<strong>        if(isset($data['rates'], $data['rates']['JPY'])) {<\/strong>\r\n\r\n<strong>            $dt = Carbon::parse($data['date']);<\/strong>\r\n<strong>            $converted_amount = round($data['rates']['JPY'] * $amount);<\/strong>\r\n<strong>            $content = \"\u3010\u7d04 \". number_format($converted_amount) .\" \u5186\u3011\u3067\u3059\".<\/strong>\r\n<strong>                $this-&gt;emoji('10002D') .\"\\n\\n\".<\/strong>\r\n<strong>                \"\uff08\". $dt-&gt;format('Y\u5e74m\u6708d\u65e5') .\"\u73fe\u5728\uff09\\n\\n\".<\/strong>\r\n<strong>                $this-&gt;emoji('100077') .\"\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u3088\u3063\u3066\u591a\u5c11\u306e\u8aa4\u5dee\u306f\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u3053\u306e\u60c5\u5831\u306f\u81ea\u5df1\u8cac\u4efb\u3067\u5229\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\";<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return $content;<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n    private function currencySymbolContent() {\r\n\r\n        $content = '';\r\n\r\n        foreach ($this-&gt;_currency_symbols as $symbol =&gt; $currency_name) {\r\n\r\n            $content .= $currency_name .\"\uff1a \". $symbol .\"\\n\";\r\n\r\n        }\r\n\r\n        return $content;\r\n\r\n    }\r\n\r\n    private function emoji($emoji_id) {\r\n\r\n        $bin = hex2bin(str_pad($emoji_id, 8, '0', STR_PAD_LEFT));\r\n        return mb_convert_encoding($bin, 'UTF-8', 'UTF-32BE');\r\n\r\n    }\r\n}<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u901a\u8ca8\u5909\u63db\u3092\u3057\u3066\u3044\u308b\u306e\u306f\u3001<code>jpyContent()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\n\u305f\u3060\u3057\u3001\u4eca\u56de\u5909\u63db\u3059\u308b\u306e\u306f\u65e5\u672c\u5186\u3067\u56fa\u5b9a\u306a\u306e\u3067\u3001\u5f15\u6570\u306f\u91d1\u984d\u3068\u5909\u63db\u5143\u306e\u901a\u8ca8\u306e\u307f\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001LINE\u3068\u306e\u901a\u4fe1\u3067\u5fc5\u8981\u306a\u60c5\u5831\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<br \/>\n\u9069\u5b9c\u5185\u5bb9\u3092\u5909\u66f4\u3057\u3066\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul>\n<li>LINE\u306e\u79d8\u5bc6\u9375\u3000\u30fb\u30fb\u30fb\u3000$channel_secret<\/li>\n<li>LINE\u306e\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3000\u30fb\u30fb\u30fb\u3000$access_token<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001<code>Foreign exchange rates API<\/code>\u306e\u901a\u8ca8\u30b7\u30f3\u30dc\u30eb\uff08\u4f8b\uff1aUSD\uff09\u306f\u5927\u6587\u5b57\u3067\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u306e\u3067\u3001<code>strtoupper()<\/code>\u3067\u5909\u63db\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u30b3\u30fc\u30c9\u3092\u30b5\u30fc\u30d0\u30fc\u306b\u30a2\u30c3\u30d7\u3057\u3066\u901a\u8ca8\u5909\u63dbLINE\u30dc\u30c3\u30c8\u3092\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u307e\u305a\u3001100\u30ab\u30ca\u30c0\u30c9\u30eb\u304b\u3089\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4543\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_2.png\" alt=\"\" width=\"1080\" height=\"748\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_2.png 1080w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_2-300x208.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_2-768x532.png 768w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_2-1024x709.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u305d\u3057\u3066\u300185\u30e6\u30fc\u30ed\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4542\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_3.png\" alt=\"\" width=\"1080\" height=\"750\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_3.png 1080w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_3-300x208.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_3-768x533.png 768w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_3-1024x711.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u306f\u3044\uff01<br \/>\n\u3069\u3061\u3089\u3082\u6210\u529f\u3067\u3059\u3002<\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\ud83d\ude0a\u2728<\/p>\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p>\u4eca\u56de\u4f5c\u3063\u305f\u901a\u8ca8\u5909\u63db\u30dc\u30c3\u30c8\u306f\u4eca\u5f8c\u3082\u516c\u958b\u3057\u7d9a\u3051\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u6d77\u5916\u65c5\u884c\u306e\u969b\u306b\u3067\u3082\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u3082\u3061\u308d\u3093\u3001\u73fe\u5730\u3067\u30b9\u30de\u30db\u304c\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u7e4b\u304c\u3089\u306a\u3044\u3068\u3060\u3081\u3067\u3059\u304c\u30fb\u30fb\u30fb\uff09<\/p>\n<p>\u3010LINE\uff1a\u65e5\u672c\u5186\u3060\u3068\u3044\u304f\u3089\uff1f\uff1f\u3011<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4541\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/exchenge_currency_1.png\" alt=\"\" width=\"187\" height=\"182\" \/><\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u4e16\u754c\u306e\u4e3b\u8981\u901a\u8ca8\u3092\u5909\u63db\u3059\u308b\u3068\u3044\u3046\u8a71\u984c\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u65e5\u672c\u306b\u4f4f\u3093\u3067\u3044\u308b\u3068\u3001\u3042\u307e\u308a\u4ed6\u56fd\u306e\u901a\u8ca8\u306b\u306f\u99b4\u67d3\u307f\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u304b\u3089\u3088\u308a\u30b0\u30ed\u30fc\u30d0\u30eb\u5316\u3082\u3059\u3059\u3080\u3067\u3057\u3087\u3046\u3057\u3001\u6d77\u5916\u65c5\u884c\u3082\u4e00\u822c\u7684\u306b\u306a\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u30c6\u30af\u30cb\u30c3\u30af\u3068\u3057\u3066\u899a\u3048\u3066\u304a\u3044\u3066\u640d\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u3084\u306f\u308a\uff11\u3064\u5fc3\u914d\u306a\u306e\u306f\u4eca\u56de\u7d39\u4ecb\u3057\u305fAPI\u304c\u3069\u3053\u307e\u3067\u5b58\u7d9a\u3059\u308b\u304b\u3067\u3059\u306d\u3002\u8abf\u3079\u305f\u3068\u3053\u308d2018\u5e74\u3042\u305f\u308a\u304b\u3089\u63d0\u4f9b\u3055\u308c\u3066\u3044\u3066<code>GitHub<\/code>\u306e\u30b9\u30bf\u30fc\u3082700\u8fd1\u3044\u4eba\u6c17\u306e\u3082\u306e\u306a\u306e\u3067\u3059\u3050\u7d42\u4e86\u3059\u308b\u3053\u3068\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304c\u3001\u3072\u3068\u3064\u306e\u4e0d\u78ba\u5b9a\u8981\u7d20\u3067\u306f\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u307e\u305f\u6642\u9593\u304c\u3067\u304d\u305f\u3089\u65e5\u672c\u306e\u53d6\u5f15\u6240\u306a\u3069\u304b\u3089\u30c7\u30fc\u30bf\u3092\u5f15\u3063\u5f35\u3063\u3066\u304f\u308b\u306a\u3069\u304c\u3067\u304d\u306a\u3044\u304b\u3092\u8abf\u67fb\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\uff08\u8a73\u3057\u3044\u65b9\u304c\u3044\u3089\u3063\u3057\u3083\u3063\u305f\u3089\u305c\u3072\u6559\u3048\u3066\u304f\u3060\u3055\u3044\ud83d\ude0a\uff09<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-427 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png\" alt=\"\" width=\"182\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png 182w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24-171x300.png 171w\" sizes=\"auto, (max-width: 182px) 100vw, 182px\" \/>\u300c\u305b\u3081\u3066A&amp;W\u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u3060\u3051\u3067\u3082\u8fd1\u304f\u306b\u6765\u306a\u3044\u304b\u306a\u30fc\uff08\u6c96\u7e04\u306b\u306f\u3042\u308b\u305d\u3046\u3067\u3059\u30fb\u30fb\u30fb\uff09\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4ee5\u524d\u79c1\u306f\u30ab\u30ca\u30c0\u306e\u30d0\u30f3\u30af\u30fc\u30d0\u30fc\u306b\u7559\u5b66\u3057\u3066\u305f\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u65e5\u672c\u306b\u5e30\u3063\u3066\u304d\u3066\u304b\u3089\u3082\u3053\u3061\u3089\u3067\u306f\u58f2\u3063\u3066\u3044\u306a\u3044\u300c\u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u300d\u3084\u300c\u30ed\u30fc\u30b9\u30c8\u3057\u305f\u3072\u307e\u308f\u308a\u306e\u7a2e\u300d &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=4538\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010PHP\u3011\u4e16\u754c\u306e\u4e3b\u8981\u901a\u8ca8\u3092\u65e5\u672c\u5186\u306b\u5909\u63db\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":4546,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,10],"tags":[134,172],"class_list":["post-4538","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-php","tag-api","tag-172"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4538"}],"version-history":[{"count":5,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4538\/revisions"}],"predecessor-version":[{"id":4547,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4538\/revisions\/4547"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/4546"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}