正在显示
24 个修改的文件
包含
1156 行增加
和
1 行删除
@@ -29,7 +29,8 @@ | @@ -29,7 +29,8 @@ | ||
29 | "phpoffice/phpexcel": "^1.8", | 29 | "phpoffice/phpexcel": "^1.8", |
30 | "ezyang/htmlpurifier": "^4.9", | 30 | "ezyang/htmlpurifier": "^4.9", |
31 | "weiwei/api-doc": "^1.6", | 31 | "weiwei/api-doc": "^1.6", |
32 | - "hooklife/thinkphp5-wechat": "^1.1" | 32 | + "hooklife/thinkphp5-wechat": "^1.1", |
33 | + "yly-openapi/yly-openapi-sdk": "v1.0.1" | ||
33 | }, | 34 | }, |
34 | "extra": { | 35 | "extra": { |
35 | }, | 36 | }, |
@@ -28,5 +28,6 @@ return array( | @@ -28,5 +28,6 @@ return array( | ||
28 | 'FontLib\\' => array($vendorDir . '/phenx/php-font-lib/src/FontLib'), | 28 | 'FontLib\\' => array($vendorDir . '/phenx/php-font-lib/src/FontLib'), |
29 | 'EasyWeChat\\' => array($vendorDir . '/overtrue/wechat/src'), | 29 | 'EasyWeChat\\' => array($vendorDir . '/overtrue/wechat/src'), |
30 | 'Dompdf\\' => array($vendorDir . '/dompdf/dompdf/src'), | 30 | 'Dompdf\\' => array($vendorDir . '/dompdf/dompdf/src'), |
31 | + 'App\\' => array($vendorDir . '/yly-openapi/yly-openapi-sdk/Lib'), | ||
31 | 'Api\\Doc\\' => array($vendorDir . '/weiwei/api-doc/src'), | 32 | 'Api\\Doc\\' => array($vendorDir . '/weiwei/api-doc/src'), |
32 | ); | 33 | ); |
@@ -83,6 +83,7 @@ class ComposerStaticInit929fb365b9981d29459d58f676689cf7 | @@ -83,6 +83,7 @@ class ComposerStaticInit929fb365b9981d29459d58f676689cf7 | ||
83 | ), | 83 | ), |
84 | 'A' => | 84 | 'A' => |
85 | array ( | 85 | array ( |
86 | + 'App\\' => 4, | ||
86 | 'Api\\Doc\\' => 8, | 87 | 'Api\\Doc\\' => 8, |
87 | ), | 88 | ), |
88 | ); | 89 | ); |
@@ -176,6 +177,10 @@ class ComposerStaticInit929fb365b9981d29459d58f676689cf7 | @@ -176,6 +177,10 @@ class ComposerStaticInit929fb365b9981d29459d58f676689cf7 | ||
176 | array ( | 177 | array ( |
177 | 0 => __DIR__ . '/..' . '/dompdf/dompdf/src', | 178 | 0 => __DIR__ . '/..' . '/dompdf/dompdf/src', |
178 | ), | 179 | ), |
180 | + 'App\\' => | ||
181 | + array ( | ||
182 | + 0 => __DIR__ . '/..' . '/yly-openapi/yly-openapi-sdk/Lib', | ||
183 | + ), | ||
179 | 'Api\\Doc\\' => | 184 | 'Api\\Doc\\' => |
180 | array ( | 185 | array ( |
181 | 0 => __DIR__ . '/..' . '/weiwei/api-doc/src', | 186 | 0 => __DIR__ . '/..' . '/weiwei/api-doc/src', |
@@ -1676,5 +1676,49 @@ | @@ -1676,5 +1676,49 @@ | ||
1676 | } | 1676 | } |
1677 | ], | 1677 | ], |
1678 | "description": "The ThinkPHP5 Api Doc Package" | 1678 | "description": "The ThinkPHP5 Api Doc Package" |
1679 | + }, | ||
1680 | + { | ||
1681 | + "name": "yly-openapi/yly-openapi-sdk", | ||
1682 | + "version": "1.0.1", | ||
1683 | + "version_normalized": "1.0.1.0", | ||
1684 | + "source": { | ||
1685 | + "type": "git", | ||
1686 | + "url": "https://github.com/Qzm6826/yilianyun-php-sdk.git", | ||
1687 | + "reference": "f9a2c780957de6f52fbbedde15e04f3ecac28793" | ||
1688 | + }, | ||
1689 | + "dist": { | ||
1690 | + "type": "zip", | ||
1691 | + "url": "https://api.github.com/repos/Qzm6826/yilianyun-php-sdk/zipball/f9a2c780957de6f52fbbedde15e04f3ecac28793", | ||
1692 | + "reference": "f9a2c780957de6f52fbbedde15e04f3ecac28793", | ||
1693 | + "shasum": "" | ||
1694 | + }, | ||
1695 | + "require": { | ||
1696 | + "php": ">=5.4.0" | ||
1697 | + }, | ||
1698 | + "require-dev": { | ||
1699 | + "phpunit/phpunit": "^4.8" | ||
1700 | + }, | ||
1701 | + "time": "2018-08-22T02:37:57+00:00", | ||
1702 | + "type": "library", | ||
1703 | + "installation-source": "dist", | ||
1704 | + "autoload": { | ||
1705 | + "psr-4": { | ||
1706 | + "App\\": "Lib/" | ||
1707 | + } | ||
1708 | + }, | ||
1709 | + "notification-url": "https://packagist.org/downloads/", | ||
1710 | + "license": [ | ||
1711 | + "MIT" | ||
1712 | + ], | ||
1713 | + "authors": [ | ||
1714 | + { | ||
1715 | + "name": "曲子陌", | ||
1716 | + "email": "lwy@yilianyun.net" | ||
1717 | + } | ||
1718 | + ], | ||
1719 | + "description": "yly-openapi-php-sdk", | ||
1720 | + "keywords": [ | ||
1721 | + "yly-openapi-php-sdk" | ||
1722 | + ] | ||
1679 | } | 1723 | } |
1680 | ] | 1724 | ] |
1 | +<?php | ||
2 | +use App\Oauth\YlyOauthClient; | ||
3 | +use App\Api\PrintService; | ||
4 | + | ||
5 | + | ||
6 | +$client = new YlyOauthClient($config); | ||
7 | + | ||
8 | +$code = ''; //开放型应用商户授权码 获取请看 http://doc2.10ss.net/371769#Code_5 | ||
9 | +if (empty($code)) {echo 'The authorization code cannot be empty';return;} | ||
10 | + | ||
11 | +try { | ||
12 | + $token = $client->getToken($code); | ||
13 | +} catch (Exception $e) { | ||
14 | + echo $e->getMessage() . "\n"; | ||
15 | + print_r(json_decode($e->getMessage(), true)); | ||
16 | + return; | ||
17 | +} | ||
18 | + | ||
19 | +$access_token = $token->access_token; //调用API凭证AccessToken | ||
20 | +$refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天 | ||
21 | +$machine_code = $token->machine_code; //商户授权机器码 | ||
22 | +$expires_in = $token->expires_in; //AccessToken失效时间30天 | ||
23 | +$origin_id = ''; //内部订单号(32位以内) | ||
24 | + | ||
25 | + | ||
26 | +if (empty($machine_code)) {echo 'The machine_code cannot be empty';return;} | ||
27 | + | ||
28 | +if (empty($origin_id)) {echo 'The origin_id cannot be empty';return;} | ||
29 | + | ||
30 | +/**文本接口开始**/ | ||
31 | +$print = new PrintService($access_token, $config); | ||
32 | +//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006 | ||
33 | +$content = "<FS2><center>**#1 美团**</center></FS2>"; | ||
34 | +$content .= str_repeat('.', 32); | ||
35 | +$content .= "<FS2><center>--在线支付--</center></FS2>"; | ||
36 | +$content .= "<FS><center>张周兄弟烧烤</center></FS>"; | ||
37 | +$content .= "订单时间:". date("Y-m-d H:i") . "\n"; | ||
38 | +$content .= "订单编号:40807050607030\n"; | ||
39 | +$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14); | ||
40 | +$content .= "<table>"; | ||
41 | +$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>"; | ||
42 | +$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>"; | ||
43 | +$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>"; | ||
44 | +$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>"; | ||
45 | +$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>"; | ||
46 | +$content .= "</table>"; | ||
47 | +$content .= str_repeat('.', 32); | ||
48 | +$content .= "<QR>这是二维码内容</QR>"; | ||
49 | +$content .= "小计:¥82\n"; | ||
50 | +$content .= "折扣:¥4 \n"; | ||
51 | +$content .= str_repeat('*', 32); | ||
52 | +$content .= "订单总价:¥78 \n"; | ||
53 | +$content .= "<FS2><center>**#1 完**</center></FS2>"; | ||
54 | + | ||
55 | +try{ | ||
56 | + var_dump($print->index($machine_code, $content, $origin_id)); | ||
57 | +}catch (Exception $e) { | ||
58 | + echo $e->getMessage(); | ||
59 | +} | ||
60 | +/**文本接口结束**/ | ||
61 | + | ||
62 | + | ||
63 | +///**图形接口开始**/ | ||
64 | +//$picturePrint = new PicturePrintService($access_token, $config); | ||
65 | +//$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg"; | ||
66 | +//try{ | ||
67 | +// var_dump($picturePrint->index($machine_code, $content, $origin_id)); | ||
68 | +//}catch (Exception $e) { | ||
69 | +// echo $e->getMessage(); | ||
70 | +//} | ||
71 | +///**图形接口结束**/ | ||
72 | + | ||
73 | + | ||
74 | +///**面单接口开始**/ //打印机型必须为k5; | ||
75 | +//$expressPrint = new ExpressPrintService($access_token, $config); | ||
76 | +//$content = array( | ||
77 | +// "OrderCode"=> "0126578665784971", | ||
78 | +// "ShipperCode"=> "SF", //SF YZPY HTKY YD | ||
79 | +// "PayType"=> 1, | ||
80 | +// "ExpType"=> 1, | ||
81 | +// "Cost"=>6.0, | ||
82 | +// "OtherCost"=> 7.0, | ||
83 | +// "CustomerName" => '1264546', | ||
84 | +// "CustomerPwd" => '4545454', | ||
85 | +// "MonthCode" => '', | ||
86 | +// "Sender"=> array( | ||
87 | +// "Company" => "5645645", | ||
88 | +// "Name" => "Taylor", | ||
89 | +// "Mobile" => "15018442396", | ||
90 | +// "ProvinceName" => "上海", | ||
91 | +// "CityName" => "上海", | ||
92 | +// "PostCode" => '61000', | ||
93 | +// "ExpAreaName" => "青浦区", | ||
94 | +// "Address" => "明珠路73号" | ||
95 | +// ), | ||
96 | +// "Receiver"=> array( | ||
97 | +// "Company"=> "789789", | ||
98 | +// "Name"=> "Yann", | ||
99 | +// "Mobile"=> "15018442396", | ||
100 | +// "ProvinceName"=> "北京", | ||
101 | +// "CityName"=> "北京", | ||
102 | +// "PostCode" => '61000', | ||
103 | +// "ExpAreaName"=> "朝阳区", | ||
104 | +// "Address"=> "三里屯街道雅秀大厦" | ||
105 | +// ), | ||
106 | +// "Commodity" => array( | ||
107 | +// array( | ||
108 | +// "GoodsName"=> "鞋子", | ||
109 | +// ) | ||
110 | +// ), | ||
111 | +// "AddService"=> array( | ||
112 | +// array( | ||
113 | +// "Name"=> "COD", | ||
114 | +// "Value"=> "1020", | ||
115 | +// "CustomerID" => "44564" | ||
116 | +// ) | ||
117 | +// ), | ||
118 | +// "StartDate" => date("y-M-d H:i:s",time() + 7200), | ||
119 | +// "Weight"=> 1.0, | ||
120 | +// "Quantity"=> 1, | ||
121 | +// "Volume"=> 0.0, | ||
122 | +// "Remark"=> "小心轻放", | ||
123 | +//); | ||
124 | +// | ||
125 | +//try{ | ||
126 | +// var_dump($expressPrint->index($machine_code, $content, $origin_id)); | ||
127 | +//}catch (Exception $e) { | ||
128 | +// echo $e->getMessage(); | ||
129 | +//} | ||
130 | +///**面单接口结束**/ |
1 | +<?php | ||
2 | +use App\Oauth\YlyOauthClient; | ||
3 | +use App\Api\PrintService; | ||
4 | +use App\Api\PicturePrintService; | ||
5 | +use App\Api\ExpressPrintService; | ||
6 | + | ||
7 | +$client = new YlyOauthClient($config); | ||
8 | +try { | ||
9 | + $token = $client->getToken(); | ||
10 | +} catch (Exception $e) { | ||
11 | + echo $e->getMessage() . "\n"; | ||
12 | + print_r(json_decode($e->getMessage(), true)); | ||
13 | + return; | ||
14 | +} | ||
15 | + | ||
16 | +$access_token = $token->access_token; //调用API凭证AccessToken 永久有效,请妥善保存. | ||
17 | +$refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天 | ||
18 | +$expires_in = $token->expires_in; //自有型应用可忽略此回调参数, AccessToken失效时间30天 | ||
19 | +$machine_code = ''; //机器码 | ||
20 | +$origin_id = ''; //内部订单号(32位以内) | ||
21 | + | ||
22 | +if (empty($machine_code)) {echo 'The machine_code cannot be empty';return;} | ||
23 | + | ||
24 | +if (empty($origin_id)) {echo 'The origin_id cannot be empty';return;} | ||
25 | + | ||
26 | + | ||
27 | +/**文本接口开始**/ | ||
28 | +$print = new PrintService($access_token, $config); | ||
29 | +//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006 | ||
30 | +$content = "<FS2><center>**#1 美团**</center></FS2>"; | ||
31 | +$content .= str_repeat('.', 32); | ||
32 | +$content .= "<FS2><center>--在线支付--</center></FS2>"; | ||
33 | +$content .= "<FS><center>张周兄弟烧烤</center></FS>"; | ||
34 | +$content .= "订单时间:". date("Y-m-d H:i") . "\n"; | ||
35 | +$content .= "订单编号:40807050607030\n"; | ||
36 | +$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14); | ||
37 | +$content .= "<table>"; | ||
38 | +$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>"; | ||
39 | +$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>"; | ||
40 | +$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>"; | ||
41 | +$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>"; | ||
42 | +$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>"; | ||
43 | +$content .= "</table>"; | ||
44 | +$content .= str_repeat('.', 32); | ||
45 | +$content .= "<QR>这是二维码内容</QR>"; | ||
46 | +$content .= "小计:¥82\n"; | ||
47 | +$content .= "折扣:¥4 \n"; | ||
48 | +$content .= str_repeat('*', 32); | ||
49 | +$content .= "订单总价:¥78 \n"; | ||
50 | +$content .= "<FS2><center>**#1 完**</center></FS2>"; | ||
51 | + | ||
52 | +try{ | ||
53 | + var_dump($print->index($machine_code, $content, $origin_id)); | ||
54 | +}catch (Exception $e) { | ||
55 | + echo $e->getMessage(); | ||
56 | +} | ||
57 | +/**文本接口结束**/ | ||
58 | + | ||
59 | + | ||
60 | +///**图形接口开始**/ | ||
61 | +//$picturePrint = new PicturePrintService($access_token, $config); | ||
62 | +//$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg"; | ||
63 | +//try{ | ||
64 | +// var_dump($picturePrint->index($machine_code, $content, $origin_id)); | ||
65 | +//}catch (Exception $e) { | ||
66 | +// echo $e->getMessage(); | ||
67 | +//} | ||
68 | +///**图形接口结束**/ | ||
69 | + | ||
70 | + | ||
71 | +///**面单接口开始**/ //打印机型必须为k5; | ||
72 | +//$expressPrint = new ExpressPrintService($access_token, $config); | ||
73 | +//$content = array( | ||
74 | +// "OrderCode"=> "0126578665784971", | ||
75 | +// "ShipperCode"=> "SF", //SF YZPY HTKY YD | ||
76 | +// "PayType"=> 1, | ||
77 | +// "ExpType"=> 1, | ||
78 | +// "Cost"=>6.0, | ||
79 | +// "OtherCost"=> 7.0, | ||
80 | +// "CustomerName" => '1264546', | ||
81 | +// "CustomerPwd" => '4545454', | ||
82 | +// "MonthCode" => '', | ||
83 | +// "Sender"=> array( | ||
84 | +// "Company" => "5645645", | ||
85 | +// "Name" => "Taylor", | ||
86 | +// "Mobile" => "15018442396", | ||
87 | +// "ProvinceName" => "上海", | ||
88 | +// "CityName" => "上海", | ||
89 | +// "PostCode" => '61000', | ||
90 | +// "ExpAreaName" => "青浦区", | ||
91 | +// "Address" => "明珠路73号" | ||
92 | +// ), | ||
93 | +// "Receiver"=> array( | ||
94 | +// "Company"=> "789789", | ||
95 | +// "Name"=> "Yann", | ||
96 | +// "Mobile"=> "15018442396", | ||
97 | +// "ProvinceName"=> "北京", | ||
98 | +// "CityName"=> "北京", | ||
99 | +// "PostCode" => '61000', | ||
100 | +// "ExpAreaName"=> "朝阳区", | ||
101 | +// "Address"=> "三里屯街道雅秀大厦" | ||
102 | +// ), | ||
103 | +// "Commodity" => array( | ||
104 | +// array( | ||
105 | +// "GoodsName"=> "鞋子", | ||
106 | +// ) | ||
107 | +// ), | ||
108 | +// "AddService"=> array( | ||
109 | +// array( | ||
110 | +// "Name"=> "COD", | ||
111 | +// "Value"=> "1020", | ||
112 | +// "CustomerID" => "44564" | ||
113 | +// ) | ||
114 | +// ), | ||
115 | +// "StartDate" => date("y-M-d H:i:s",time() + 7200), | ||
116 | +// "Weight"=> 1.0, | ||
117 | +// "Quantity"=> 1, | ||
118 | +// "Volume"=> 0.0, | ||
119 | +// "Remark"=> "小心轻放", | ||
120 | +//); | ||
121 | +// | ||
122 | +//try{ | ||
123 | +// var_dump($expressPrint->index($machine_code, $content, $origin_id)); | ||
124 | +//}catch (Exception $e) { | ||
125 | +// echo $e->getMessage(); | ||
126 | +//} | ||
127 | +///**面单接口结束**/ |
1 | +<?php | ||
2 | + | ||
3 | +include dirname(__DIR__) . '/Lib/Autoloader.php'; | ||
4 | +use App\Config\YlyConfig; | ||
5 | + | ||
6 | +$grantType = 'client_credentials'; //'client_credentials' 自有型应用; 'authorization_code' 开放型应用 | ||
7 | +define('GRANTTYPE', $grantType); | ||
8 | + | ||
9 | + | ||
10 | +$clientId = ''; //应用id | ||
11 | +$clientSecret = ''; //应用密钥 | ||
12 | + | ||
13 | + | ||
14 | +$config = new YlyConfig($clientId, $clientSecret); |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +class ExpressPrintService extends RpcService{ | ||
6 | + | ||
7 | + /** | ||
8 | + * 面单打印接口 | ||
9 | + * 不支持机型: k4-wh, k4-wa, m1 (k4系列机型不建议使用不干胶热敏纸) | ||
10 | + * | ||
11 | + * @param $machineCode string 机器码 | ||
12 | + * @param $content array 面单数据 | ||
13 | + * @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母 | ||
14 | + * @return mixed | ||
15 | + */ | ||
16 | + public function index($machineCode, $content, $originId) | ||
17 | + { | ||
18 | + return $this->client->call('expressprint/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId)); | ||
19 | + } | ||
20 | + | ||
21 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +class OauthService extends RpcService{ | ||
6 | + | ||
7 | + | ||
8 | + /** | ||
9 | + * 设置推送URL接口 | ||
10 | + * | ||
11 | + * @param $cmd string 推送队列键 | ||
12 | + * @param $url string 推送地址 | ||
13 | + * @param $status string 推送开关 | ||
14 | + * @return mixed | ||
15 | + */ | ||
16 | + public function setPushUrl($cmd, $url, $status = 'open') | ||
17 | + { | ||
18 | + return $this->client->call('oauth/setpushurl', array('cmd' => $cmd, 'url' => $url, 'status' => $status)); | ||
19 | + } | ||
20 | +} | ||
21 | + | ||
22 | + |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +class PicturePrintService extends RpcService{ | ||
6 | + | ||
7 | + | ||
8 | + /** | ||
9 | + * 图形打印接口 | ||
10 | + * 不支持机型: k4-wh, k4-wa, m1 | ||
11 | + * | ||
12 | + * @param $machineCode string 机器码 | ||
13 | + * @param $pictureUrl string 图片链接地址 | ||
14 | + * @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母 | ||
15 | + * @return mixed | ||
16 | + */ | ||
17 | + public function index($machineCode, $pictureUrl, $originId) | ||
18 | + { | ||
19 | + return $this->client->call('pictureprint/index', array('machine_code' => $machineCode, 'picture_url' => $pictureUrl, 'origin_id' => $originId)); | ||
20 | + } | ||
21 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +class PrintMenuService extends RpcService{ | ||
6 | + | ||
7 | + /** | ||
8 | + * 添加应用菜单接口 | ||
9 | + * | ||
10 | + * @param $machineCode string 机器码 | ||
11 | + * @param $content string 菜单详情(json) | ||
12 | + * @return mixed | ||
13 | + */ | ||
14 | + public function addPrintMenu($machineCode, $content) | ||
15 | + { | ||
16 | + return $this->client->call('printmenu/addprintmenu', array('machine_code' => $machineCode, 'content' => $content)); | ||
17 | + } | ||
18 | + | ||
19 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +class PrintService extends RpcService{ | ||
6 | + | ||
7 | + /** | ||
8 | + * 打印接口 | ||
9 | + * | ||
10 | + * @param $machineCode string 机器码 | ||
11 | + * @param $content string 打印内容 | ||
12 | + * @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母 | ||
13 | + * @return mixed | ||
14 | + */ | ||
15 | + public function index($machineCode, $content, $originId) | ||
16 | + { | ||
17 | + return $this->client->call('print/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId)); | ||
18 | + } | ||
19 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +class PrinterService extends RpcService{ | ||
6 | + | ||
7 | + /** | ||
8 | + * 自有型应用授权终端 | ||
9 | + * | ||
10 | + * @param $machineCode string 机器码 | ||
11 | + * @param $mSign string 机器密钥 | ||
12 | + * @param string $printName 打印机昵称 | ||
13 | + * @param string $phone gprs卡号 | ||
14 | + * @return mixed | ||
15 | + */ | ||
16 | + public function addPrinter($machineCode, $mSign, $printName = '', $phone = '') | ||
17 | + { | ||
18 | + $params = array( | ||
19 | + 'machine_code' => $machineCode, | ||
20 | + 'msign' => $mSign, | ||
21 | + ); | ||
22 | + if (!empty($phone)) { | ||
23 | + $params['phone'] = $phone; | ||
24 | + } | ||
25 | + if (!empty($printName)) { | ||
26 | + $params['print_name'] = $printName; | ||
27 | + } | ||
28 | + return $this->client->call('printer/addprinter', $params); | ||
29 | + } | ||
30 | + | ||
31 | + | ||
32 | + /** | ||
33 | + * 设置内置语音接口 | ||
34 | + * 注意: 仅支持K4-WA、K4-GAD、K4-WGEAD型号 | ||
35 | + * | ||
36 | + * @param $machineCode string 机器码 | ||
37 | + * @param $content string 在线语音地址链接 or 自定义语音内容 | ||
38 | + * @param bool $isFile true or false | ||
39 | + * @param string $aid int 0~9 , 定义需设置的语音编号,若不提交,默认升序 | ||
40 | + * @return mixed | ||
41 | + */ | ||
42 | + public function setVoice($machineCode, $content, $isFile = false, $aid = '') | ||
43 | + { | ||
44 | + $params = array( | ||
45 | + 'machine_code' => $machineCode, | ||
46 | + 'content' => $content, | ||
47 | + 'is_file' => $isFile, | ||
48 | + ); | ||
49 | + if (!empty($aid)){ | ||
50 | + $params ['aid'] = $aid; | ||
51 | + } | ||
52 | + return $this->client->call('printer/setvoice', $params); | ||
53 | + } | ||
54 | + | ||
55 | + | ||
56 | + /** | ||
57 | + * 删除内置语音接口 | ||
58 | + * 注意: 仅支持K4-WA、K4-GAD、K4-WGEAD型号 | ||
59 | + * | ||
60 | + * @param $machineCode string 机器码 | ||
61 | + * @param $aid int 0 ~ 9 编号 | ||
62 | + * @return mixed | ||
63 | + */ | ||
64 | + public function deleteVoice($machineCode, $aid) | ||
65 | + { | ||
66 | + return $this->client->call('printer/deletevoice', array('machine_code' => $machineCode, 'aid' => $aid)); | ||
67 | + } | ||
68 | + | ||
69 | + | ||
70 | + /** | ||
71 | + * 删除终端授权接口 | ||
72 | + * | ||
73 | + * @param $machineCode string 机器码 | ||
74 | + * @return mixed | ||
75 | + */ | ||
76 | + public function deletePrinter($machineCode) | ||
77 | + { | ||
78 | + return $this->client->call('printer/deleteprinter', array('machine_code' => $machineCode)); | ||
79 | + } | ||
80 | + | ||
81 | + | ||
82 | + /** | ||
83 | + * 关机重启接口 | ||
84 | + * | ||
85 | + * @param $machineCode string 机器码 | ||
86 | + * @param $responseType string restart or shutdown | ||
87 | + * @return mixed | ||
88 | + */ | ||
89 | + public function shutdownRestart($machineCode, $responseType) | ||
90 | + { | ||
91 | + return $this->client->call('printer/shutdownrestart', array('machine_code' => $machineCode, 'response_type' => $responseType)); | ||
92 | + } | ||
93 | + | ||
94 | + | ||
95 | + /** | ||
96 | + * 声音调节接口 | ||
97 | + * | ||
98 | + * @param $machineCode string 机器码 | ||
99 | + * @param $voice string 音量 0 or 1 or 2 or 3 | ||
100 | + * @param $responseType string buzzer (蜂鸣器) or horn (喇叭) | ||
101 | + * @return mixed | ||
102 | + */ | ||
103 | + public function setsound($machineCode, $voice, $responseType) | ||
104 | + { | ||
105 | + return $this->client->call('printer/setsound', array('machine_code' => $machineCode, 'voice' => $voice, 'response_type' => $responseType)); | ||
106 | + } | ||
107 | + | ||
108 | + | ||
109 | + /** | ||
110 | + * 获取机型打印宽度接口 | ||
111 | + * | ||
112 | + * @param $machineCode string 机器码 | ||
113 | + * @return mixed | ||
114 | + */ | ||
115 | + public function printInfo($machineCode) | ||
116 | + { | ||
117 | + return $this->client->call('printer/printinfo', array('machine_code' => $machineCode)); | ||
118 | + } | ||
119 | + | ||
120 | + | ||
121 | + /** | ||
122 | + * 获取机型软硬件版本接口 | ||
123 | + * | ||
124 | + * @param $machineCode string 机器码 | ||
125 | + * @return mixed | ||
126 | + */ | ||
127 | + public function getVersion($machineCode) | ||
128 | + { | ||
129 | + return $this->client->call('printer/getversion', array('machine_code' => $machineCode)); | ||
130 | + } | ||
131 | + | ||
132 | + | ||
133 | + /** | ||
134 | + * 取消所有未打印订单接口 | ||
135 | + * | ||
136 | + * @param $machineCode string 机器码 | ||
137 | + * @return mixed | ||
138 | + */ | ||
139 | + public function cancelAll($machineCode) | ||
140 | + { | ||
141 | + return $this->client->call('printer/cancelall', array('machine_code' => $machineCode)); | ||
142 | + } | ||
143 | + | ||
144 | + | ||
145 | + /** | ||
146 | + * 取消单条未打印订单接口 | ||
147 | + * | ||
148 | + * @param $machineCode string 机器码 | ||
149 | + * @param $orderId string 未打印的易联云ID | ||
150 | + * @return mixed | ||
151 | + */ | ||
152 | + public function cancelOne($machineCode, $orderId) | ||
153 | + { | ||
154 | + return $this->client->call('printer/cancelone', array('machine_code' => $machineCode, 'order_id' => $orderId)); | ||
155 | + } | ||
156 | + | ||
157 | + | ||
158 | + /** | ||
159 | + * 设置logo接口 | ||
160 | + * | ||
161 | + * @param $machineCode string 机器码 | ||
162 | + * @param $imgUrl string logo链接地址 | ||
163 | + * @return mixed | ||
164 | + */ | ||
165 | + public function setIcon($machineCode, $imgUrl) | ||
166 | + { | ||
167 | + return $this->client->call('printer/seticon', array('machine_code' => $machineCode, 'img_url' => $imgUrl)); | ||
168 | + } | ||
169 | + | ||
170 | + | ||
171 | + /** | ||
172 | + * 取消logo接口 | ||
173 | + * | ||
174 | + * @param $machineCode string 机器码 | ||
175 | + * @return mixed | ||
176 | + */ | ||
177 | + public function deleteIcon($machineCode) | ||
178 | + { | ||
179 | + return $this->client->call('printer/deleteicon', array('machine_code' => $machineCode)); | ||
180 | + } | ||
181 | + | ||
182 | + | ||
183 | + /** | ||
184 | + * 打印方式接口 | ||
185 | + * | ||
186 | + * @param $machineCode string 机器码 | ||
187 | + * @param $responseType string btnopen or btnclose | ||
188 | + * @return mixed | ||
189 | + */ | ||
190 | + public function btnPrint($machineCode, $responseType) | ||
191 | + { | ||
192 | + return $this->client->call('printer/btnprint', array('machine_code' => $machineCode, 'response_type' => $responseType)); | ||
193 | + } | ||
194 | + | ||
195 | + | ||
196 | + /** | ||
197 | + * 接单拒单设置接口 | ||
198 | + * | ||
199 | + * @param $machineCode string 机器码 | ||
200 | + * @param $responseType string open or close | ||
201 | + * @return mixed | ||
202 | + */ | ||
203 | + public function getOrder($machineCode, $responseType) | ||
204 | + { | ||
205 | + return $this->client->call('printer/getorder', array('machine_code' => $machineCode, 'response_type' => $responseType)); | ||
206 | + } | ||
207 | + | ||
208 | + | ||
209 | + /** | ||
210 | + * 获取订单状态接口 | ||
211 | + * | ||
212 | + * @param $machineCode string 机器码 | ||
213 | + * @param $orderId string 易联云订单id | ||
214 | + * @return mixed | ||
215 | + */ | ||
216 | + public function getOrderStatus($machineCode, $orderId) | ||
217 | + { | ||
218 | + return $this->client->call('printer/getorderstatus', array('machine_code' => $machineCode, 'order_id' => $orderId)); | ||
219 | + } | ||
220 | + | ||
221 | + | ||
222 | + /** | ||
223 | + * 获取订单列表接口 | ||
224 | + * | ||
225 | + * @param $machineCode string 机器码 | ||
226 | + * @param $pageIndex int 第几页 | ||
227 | + * @param $pageSize int 查询条数 | ||
228 | + * @return mixed | ||
229 | + */ | ||
230 | + public function getOrderPagingList($machineCode, $pageIndex = 1 , $pageSize = 10) | ||
231 | + { | ||
232 | + return $this->client->call('printer/getorderpaginglist', array('machine_code' => $machineCode, 'page_index' => $pageIndex, 'page_size' => $pageSize)); | ||
233 | + } | ||
234 | + | ||
235 | + | ||
236 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Api; | ||
4 | + | ||
5 | +use App\Config\YlyConfig; | ||
6 | +use App\Protocol\YlyRpcClient; | ||
7 | + | ||
8 | +class RpcService{ | ||
9 | + | ||
10 | + protected $client; | ||
11 | + | ||
12 | + public function __construct($token, YlyConfig $config) | ||
13 | + { | ||
14 | + $this->client = new YlyRpcClient($token, $config); | ||
15 | + } | ||
16 | + | ||
17 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App; | ||
4 | + | ||
5 | +class Autoloader{ | ||
6 | + | ||
7 | + public static function loadByNamespace($name) | ||
8 | + { | ||
9 | + $class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name); | ||
10 | + if (strpos($name, 'App\\') === 0) { | ||
11 | + $class_file = __DIR__ . substr($class_path, strlen('App')) . '.php'; | ||
12 | + }elseif(empty($class_file) || !is_file($class_file)){ | ||
13 | + $class_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $class_path . ".php"; | ||
14 | + } | ||
15 | + if (is_file($class_file)) { | ||
16 | + require_once ($class_file); | ||
17 | + if (class_exists($name, false)) { | ||
18 | + return true; | ||
19 | + } | ||
20 | + } | ||
21 | + return false; | ||
22 | + | ||
23 | + } | ||
24 | + | ||
25 | +} | ||
26 | + | ||
27 | +spl_autoload_register('\App\Autoloader::loadByNamespace'); | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | ||
32 | + |
1 | +<?php | ||
2 | + | ||
3 | + | ||
4 | +namespace App\Config; | ||
5 | + | ||
6 | +use InvalidArgumentException; | ||
7 | +class YlyConfig{ | ||
8 | + | ||
9 | + private $clientId = ''; | ||
10 | + private $clientSecret = ''; | ||
11 | + private $requestUrl = "https://open-api.10ss.net"; | ||
12 | + private $log; | ||
13 | + | ||
14 | + public function __construct($clientId, $clientSecret) | ||
15 | + { | ||
16 | + | ||
17 | + if ($clientId == null || $clientId == "") { | ||
18 | + throw new InvalidArgumentException("clientId is required"); | ||
19 | + } | ||
20 | + | ||
21 | + if ($clientSecret == null || $clientSecret == "") { | ||
22 | + throw new InvalidArgumentException("clientSecret is required"); | ||
23 | + } | ||
24 | + | ||
25 | + $this->clientId = $clientId; | ||
26 | + $this->clientSecret = $clientSecret; | ||
27 | + } | ||
28 | + | ||
29 | + public function getClientId() | ||
30 | + { | ||
31 | + return $this->clientId; | ||
32 | + } | ||
33 | + | ||
34 | + | ||
35 | + public function getClientSecret() | ||
36 | + { | ||
37 | + return $this->clientSecret; | ||
38 | + } | ||
39 | + | ||
40 | + public function getRequestUrl() | ||
41 | + { | ||
42 | + return $this->requestUrl; | ||
43 | + } | ||
44 | + | ||
45 | + public function setRequestUrl($requestUrl) | ||
46 | + { | ||
47 | + $this->requestUrl = $requestUrl; | ||
48 | + } | ||
49 | + | ||
50 | + public function getLog() | ||
51 | + { | ||
52 | + return $this->log; | ||
53 | + } | ||
54 | + | ||
55 | + public function setLog($log) | ||
56 | + { | ||
57 | + if (!method_exists($log, "info")) { | ||
58 | + throw new InvalidArgumentException("logger need have method 'info(\$message)'"); | ||
59 | + } | ||
60 | + if (!method_exists($log, "error")) { | ||
61 | + throw new InvalidArgumentException("logger need have method 'error(\$message)'"); | ||
62 | + } | ||
63 | + $this->log = $log; | ||
64 | + } | ||
65 | + | ||
66 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Oauth; | ||
4 | + | ||
5 | +use App\Config\YlyConfig; | ||
6 | +use Exception; | ||
7 | +class YlyOauthClient{ | ||
8 | + | ||
9 | + private $clientId; | ||
10 | + private $clientSecret; | ||
11 | + private $tokenUrl; | ||
12 | + private $log; | ||
13 | + | ||
14 | + | ||
15 | + public function __construct(YlyConfig $config) | ||
16 | + { | ||
17 | + $this->clientId = $config->getClientId(); | ||
18 | + $this->clientSecret = $config->getClientSecret(); | ||
19 | + $this->tokenUrl = $config->getRequestUrl() . '/oauth/oauth'; | ||
20 | + $this->log = $config->getLog(); | ||
21 | + } | ||
22 | + | ||
23 | + | ||
24 | + public function getToken($code = '') | ||
25 | + { | ||
26 | + $time = time(); | ||
27 | + $params = array( | ||
28 | + 'client_id' => $this->clientId, | ||
29 | + 'timestamp' => $time, | ||
30 | + 'sign' => $this->getSign($time), | ||
31 | + 'id' => $this->uuid4(), | ||
32 | + 'scope' => 'all' | ||
33 | + ); | ||
34 | + $params['grant_type'] = 'client_credentials'; | ||
35 | + if (!empty($code)) { | ||
36 | + $params['code'] = $code; | ||
37 | + $params['grant_type'] = 'authorization_code'; | ||
38 | + } | ||
39 | + return $this->send($params); | ||
40 | + } | ||
41 | + | ||
42 | + | ||
43 | + public function refreshToken($refreshToken) | ||
44 | + { | ||
45 | + $time = time(); | ||
46 | + $params = array( | ||
47 | + 'client_id' => $this->clientId, | ||
48 | + 'timestamp' => $time, | ||
49 | + 'sign' => $this->getSign($time), | ||
50 | + 'id' => $this->uuid4(), | ||
51 | + 'scope' => 'all', | ||
52 | + 'grant_type' => 'refresh_token', | ||
53 | + 'refresh_token' => $refreshToken, | ||
54 | + ); | ||
55 | + return $this->send($params); | ||
56 | + } | ||
57 | + | ||
58 | + | ||
59 | + public function getSign($timestamp) | ||
60 | + { | ||
61 | + return md5( | ||
62 | + $this->clientId. | ||
63 | + $timestamp. | ||
64 | + $this->clientSecret | ||
65 | + ); | ||
66 | + } | ||
67 | + | ||
68 | + | ||
69 | + public function uuid4(){ | ||
70 | + mt_srand((double)microtime() * 10000); | ||
71 | + $charid = strtolower(md5(uniqid(rand(), true))); | ||
72 | + $hyphen = '-'; | ||
73 | + $uuidV4 = | ||
74 | + substr($charid, 0, 8) . $hyphen . | ||
75 | + substr($charid, 8, 4) . $hyphen . | ||
76 | + substr($charid, 12, 4) . $hyphen . | ||
77 | + substr($charid, 16, 4) . $hyphen . | ||
78 | + substr($charid, 20, 12); | ||
79 | + return $uuidV4; | ||
80 | + } | ||
81 | + | ||
82 | + | ||
83 | + public function send($data) | ||
84 | + { | ||
85 | + $requestInfo = http_build_query($data); | ||
86 | + $log = $this->log; | ||
87 | + if ($log != null) { | ||
88 | + $log->info("request data: " . $requestInfo); | ||
89 | + } | ||
90 | + $curl = curl_init(); // 启动一个CURL会话 | ||
91 | + curl_setopt($curl, CURLOPT_URL, $this->tokenUrl); // 要访问的地址 | ||
92 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测 | ||
93 | + curl_setopt($curl, CURLOPT_HTTPHEADER, array( | ||
94 | + 'Expect:' | ||
95 | + )); // 解决数据包大不能提交 | ||
96 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 | ||
97 | + curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer | ||
98 | + curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 | ||
99 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $requestInfo); // Post提交的数据包 | ||
100 | + curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循 | ||
101 | + curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 | ||
102 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 | ||
103 | + $requestResponse = curl_exec($curl); // 执行操作 | ||
104 | + $response = json_decode($requestResponse); | ||
105 | + if (curl_errno($curl)) { | ||
106 | + if ($log != null) { | ||
107 | + $log->error("error: " . curl_error($curl)); | ||
108 | + } | ||
109 | + throw new Exception(curl_error($curl)); | ||
110 | + } | ||
111 | + if (is_null($response)) { | ||
112 | + throw new Exception("illegal response :" . $requestResponse); | ||
113 | + } | ||
114 | + if ($response->error != 0 && $response->error_description != 'success') { | ||
115 | + throw new Exception(json_encode($response)); | ||
116 | + } | ||
117 | + if ($this->log != null) { | ||
118 | + $this->log->info("response: " . json_encode($response)); | ||
119 | + } | ||
120 | + curl_close($curl); // 关键CURL会话 | ||
121 | + return $response->body; // 返回数据 | ||
122 | + } | ||
123 | + | ||
124 | + | ||
125 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Protocol; | ||
4 | + | ||
5 | +use App\Config\YlyConfig; | ||
6 | +use Exception; | ||
7 | +class YlyRpcClient{ | ||
8 | + | ||
9 | + private $clientId; | ||
10 | + private $clientSecret; | ||
11 | + private $requestUrl; | ||
12 | + private $token; | ||
13 | + private $log; | ||
14 | + | ||
15 | + | ||
16 | + public function __construct($token, YlyConfig $config) | ||
17 | + { | ||
18 | + $this->clientId = $config->getClientId(); | ||
19 | + $this->clientSecret = $config->getClientSecret(); | ||
20 | + $this->requestUrl = $config->getRequestUrl(); | ||
21 | + $this->log = $config->getLog(); | ||
22 | + $this->token = $token; | ||
23 | + } | ||
24 | + | ||
25 | + | ||
26 | + public function call($action, array $params) | ||
27 | + { | ||
28 | + $time = time(); | ||
29 | + $params = array_merge(array( | ||
30 | + 'client_id' => $this->clientId, | ||
31 | + 'timestamp' => $time, | ||
32 | + 'sign' => $this->getSign($time), | ||
33 | + 'id' => $this->uuid4(), | ||
34 | + 'access_token' => $this->token, | ||
35 | + ), $params); | ||
36 | + $result = $this->send($params, $this->requestUrl . '/' .$action); | ||
37 | + $response = json_decode($result, false, 512, JSON_BIGINT_AS_STRING); | ||
38 | + if (is_null($response)) { | ||
39 | + throw new Exception("invalid response."); | ||
40 | + } | ||
41 | + if ( | ||
42 | + isset($response->error) && | ||
43 | + $response->error != 0 | ||
44 | + ){ | ||
45 | + $errorDescription = isset($response->body) ? $response->error_description . $response->body : $response->error_description; | ||
46 | + throw new Exception('Call method ' . $action . ' error code is ' . $response->error . ' error message is ' . $errorDescription); | ||
47 | + } | ||
48 | + | ||
49 | + return $response; | ||
50 | + } | ||
51 | + | ||
52 | + | ||
53 | + public function getSign($timestamp) | ||
54 | + { | ||
55 | + return md5( | ||
56 | + $this->clientId. | ||
57 | + $timestamp. | ||
58 | + $this->clientSecret | ||
59 | + ); | ||
60 | + } | ||
61 | + | ||
62 | + | ||
63 | + public function uuid4(){ | ||
64 | + mt_srand((double)microtime() * 10000); | ||
65 | + $charid = strtolower(md5(uniqid(rand(), true))); | ||
66 | + $hyphen = '-'; | ||
67 | + $uuidV4 = | ||
68 | + substr($charid, 0, 8) . $hyphen . | ||
69 | + substr($charid, 8, 4) . $hyphen . | ||
70 | + substr($charid, 12, 4) . $hyphen . | ||
71 | + substr($charid, 16, 4) . $hyphen . | ||
72 | + substr($charid, 20, 12); | ||
73 | + return $uuidV4; | ||
74 | + } | ||
75 | + | ||
76 | + | ||
77 | + public function send($data,$url) | ||
78 | + { | ||
79 | + $requestInfo = http_build_query($data); | ||
80 | + $log = $this->log; | ||
81 | + if ($log != null) { | ||
82 | + $log->info("request data: " . $requestInfo); | ||
83 | + } | ||
84 | + $curl = curl_init(); // 启动一个CURL会话 | ||
85 | + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 | ||
86 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测 | ||
87 | + curl_setopt($curl, CURLOPT_HTTPHEADER, array( | ||
88 | + 'Expect:' | ||
89 | + )); // 解决数据包大不能提交 | ||
90 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 | ||
91 | + curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer | ||
92 | + curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 | ||
93 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $requestInfo); // Post提交的数据包 | ||
94 | + curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循 | ||
95 | + curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 | ||
96 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 | ||
97 | + $response = curl_exec($curl); // 执行操作 | ||
98 | + if (curl_errno($curl)) { | ||
99 | + if ($log != null) { | ||
100 | + $log->error("error: " . curl_error($curl)); | ||
101 | + } | ||
102 | + throw new Exception(curl_error($curl)); | ||
103 | + } | ||
104 | + if ($log != null) { | ||
105 | + $log->info("response: " . $response); | ||
106 | + } | ||
107 | + curl_close($curl); // 关键CURL会话 | ||
108 | + return $response; // 返回数据 | ||
109 | + } | ||
110 | + | ||
111 | + | ||
112 | + | ||
113 | +} |
1 | +<h1 align="center">yilianyun-php-sdk</h1> | ||
2 | +<p align="center"> | ||
3 | +<a href="https://travis-ci.org/Qzm6826/yilianyun-php-sdk"><img src="https://travis-ci.org/Qzm6826/yilianyun-php-sdk.svg?branch=master" alt="Build Status"></a> | ||
4 | +</p> | ||
5 | + | ||
6 | +# Requirement | ||
7 | + | ||
8 | +``` | ||
9 | +PHP >= 5.4 | ||
10 | +``` | ||
11 | +# Installation | ||
12 | + | ||
13 | +```shell | ||
14 | +composer require yly-openapi/yly-openapi-sdk:dev-master | ||
15 | +``` | ||
16 | + | ||
17 | +若composer失败,请换到国内镜像 | ||
18 | +```shell | ||
19 | +composer config -g repo.packagist composer https://packagist.laravel-china.org | ||
20 | +``` | ||
21 | + | ||
22 | +# Usage | ||
23 | + 1. 接口类Lib/Api/*.php,集成了所有的易联云接口 | ||
24 | + 2. 配置类Lib/Config/YlyConfig.php | ||
25 | + 3. 授权类Lib/Oauth/YlyOauthClient.php,获取调用凭证AccessToken,每日上限次数20次,24小时后更新次数 | ||
26 | + 4. 接口调用类Lib/Protocol/YlyRpcClient.php,包括了md5工具函数,Sign工具函数,uuid函数,可以直接用这个类直接进行接口调用 | ||
27 | + 5. 若觉的好用,大佬们请在<a href= 'https://github.com/Qzm6826/yilianyun-php-sdk'>GitHub</a>上给小曲一个Star,在此小曲先感谢各位大佬了,小曲也会时长更新接口的,为大佬们提供方便! | ||
28 | + | ||
29 | +```php | ||
30 | +<?php | ||
31 | +//composer下加载方式 | ||
32 | +include_once __DIR__ . "/vendor/autoload.php"; | ||
33 | + | ||
34 | +//gitHub下载加载方式 | ||
35 | +include_once __DIR__ . "/Lib/Autoloader.php"; | ||
36 | + | ||
37 | +//初始化配置 | ||
38 | +use App\Config\YlyConfig; | ||
39 | +$config = new YlyConfig('你的应用id', '你的应用密钥'); | ||
40 | + | ||
41 | +//获取token | ||
42 | +use App\Oauth\YlyOauthClient; | ||
43 | +$client = new YlyOauthClient($config); | ||
44 | +$token = $client->getToken(); //若是开放型应用请传授权码code | ||
45 | +var_dump($token); | ||
46 | + | ||
47 | +//授权打印机(自有型应用使用,开放型应用请跳过该步骤) | ||
48 | +use App\Api\PrinterService; | ||
49 | +$printer = new PrinterService($token->access_token, $config); | ||
50 | +$data = $printer->addPrinter('你的机器码', '你的机器密钥', '机器昵称也可不填', 'gprs卡号没有可不填'); | ||
51 | +var_dump($data); | ||
52 | + | ||
53 | + | ||
54 | +//调取文本打印 | ||
55 | +use App\Api\PrintService; | ||
56 | +$print = new PrintService($token->access_token, $config); | ||
57 | +$data = $print->index('你的机器码','打印内容排版可看Demo下的callback.php','你的系统内部id自定义32位以内'); | ||
58 | +var_dump($data); | ||
59 | + | ||
60 | +//调取图形打印 | ||
61 | +use App\Api\PicturePrintService; | ||
62 | +$print = new PicturePrintService($token->access_token, $config); | ||
63 | +$data = $print->index('你的机器码','打印内容排版可看Demo下的callback.php','你的系统内部id自定义32位以内'); | ||
64 | +var_dump($data); | ||
65 | + | ||
66 | +``` |
1 | +{ | ||
2 | + "name": "yly-openapi/yly-openapi-sdk", | ||
3 | + "description": "yly-openapi-php-sdk", | ||
4 | + "license": "MIT", | ||
5 | + "keywords": [ | ||
6 | + "yly-openapi-php-sdk" | ||
7 | + ], | ||
8 | + "version": "1.0.1", | ||
9 | + "authors": [ | ||
10 | + { | ||
11 | + "name": "曲子陌", | ||
12 | + "email": "lwy@yilianyun.net" | ||
13 | + } | ||
14 | + ], | ||
15 | + "require": { | ||
16 | + "php": ">=5.4.0" | ||
17 | + }, | ||
18 | + "require-dev": { | ||
19 | + "phpunit/phpunit": "^4.8" | ||
20 | + }, | ||
21 | + "autoload": { | ||
22 | + "psr-4": {"App\\": "Lib/"} | ||
23 | + } | ||
24 | +} |
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<phpunit backupGlobals="false" | ||
3 | + backupStaticAttributes="false" | ||
4 | + bootstrap="vendor/autoload.php" | ||
5 | + colors="true" | ||
6 | + convertErrorsToExceptions="true" | ||
7 | + convertNoticesToExceptions="true" | ||
8 | + convertWarningsToExceptions="true" | ||
9 | + processIsolation="false" | ||
10 | + stopOnFailure="false" | ||
11 | + syntaxCheck="false"> | ||
12 | + <testsuites> | ||
13 | + <testsuite name="Application Test Suite"> | ||
14 | + <directory>./tests/</directory> | ||
15 | + </testsuite> | ||
16 | + </testsuites> | ||
17 | + <filter> | ||
18 | + <whitelist> | ||
19 | + <directory suffix=".php">src/</directory> | ||
20 | + </whitelist> | ||
21 | + </filter> | ||
22 | +</phpunit> |
-
请 注册 或 登录 后发表评论