This is after watching Overtrue’s “LX2 PHP Expansion Pack Practical Tutorial from Getting Started to Release” course. But unit tests and automated tests haven’t been written yet, this part is just learning, still struggling.

Source address: Overnaive /DingTalkRobot

Requirement

  • PHP > = 7.2.5
  • Composer

Installation

Composer require overnaive/dingtalkrobot ^ 1.0

Documents

Nail the official documentation

Usage

<? php use DingTalkRobot\DingTalkRobot; $robot = new DingTalkRobot(['access_token' => 'access_token_string', 'secret' => 'secret_string',]); $result = $robot->message-> text-> setTextContent(' I am I, I am I, '); Is not the same as fireworks @156XXXX8827 ') -> AddatMobile (' 156XXXX8827 ') -> Send (); $result = $robot-> message-> send([' msgType '=> 'text', 'text' => ['content' =>']), $result = $robot-> message-> send([' msgType '=> 'text', 'text' => ['content' =>']), ], 'atMobiles' => [ '156xxxx8827' ], 'isAtAll' => false, ]);

Example

<? php use DingTalkRobot\DingTalkRobot; $robot = new DingTalkRobot(['access_token' => 'access_token_string', 'secret' => 'secret_string',]); $result = $robot-bb0 message-> message-> setTextContent(' I am I, I am I, '); Is not the same as fireworks @156XXXX8827 ') -> AddatMobile (' 156XXXX8827 ') -> AddatMobile (' 189XXXX8325 ') -> Send (); var_dump($result); // $result = $robot->message-> link-> setTitle(' Time goes on ') ->setText(' This new version is coming soon, the creator calls it mangrove. Before that, product managers used a code name for every major upgrade, and this time, Why Mangroves ') ->setMessageUrl('https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97 a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&versi on=26031933&nettype=WIFI') ->send(); var_dump($result); $result = $/ / markdown type robot - > message - > markdown - > setTitle (' the weather in hangzhou) - > setText (" @ # # # # hangzhou weather 18150089296 \ n > 9 degrees, from grade 1, Air fine 89, relative temperature 73%. [screenshot] (https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \ n > # # # # # # 10 p.m [weather] (https://www.dingtalk.com) \ n ") - > addAtMobile (' 150 XXXXXXXX ') - > send (); var_dump($result); $result = $robot->message-> actioncard-> setTitle(' Jobs wanted to build an Apple Cafe 20 years ago, Which was the predecessor of the Apple Store ') ->setText("! [screenshot] (https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png) # # # 20 years ago to create jobs Apple Apple Store cafe The design of the design is changing from the original full of technology to life, But its life actually can be traced back to the direction of the apple's plan to build the cafe a "20 years ago) - > addBtn (' se ', 'https://www.dingtalk.com/') - > verticalBtn () - > send (); var_dump($result); $result = $robot->message-> actioncard-> setTitle(' Jobs wanted to build an Apple Cafe 20 years ago, Which was the predecessor of the Apple Store ') ->setText("! [screenshot] (https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png) # # # 20 years ago to create jobs Apple Apple Store cafe The design of the design is changing from the original full of technology to life, And its life actually can be traced back to the direction of the apple's plan to build the cafe a "20 years ago) - > verticalBtn () - > addBtn (content of 'good', 'https://www.dingtalk.com/') - > addBtn (' not interested in, 'https://www.dingtalk.com/') ->send(); var_dump($result); $result = $robot->message-> feedcard-> addLink($robot->message-> feedcard-> addLink($robot->message-> feedcard-> addLink), 'https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srci d=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nett Ype = WIFI ', 'https://gw.alicdn.com/tfs/TB1ayl9mpYqK1RjSZLeXXbXppXa-170-62.png') - > addLink (a train 2 'forward' age, 'https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srci d=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nett ype=WIFI', 'https://gw.alicdn.com/tfs/TB1ayl9mpYqK1RjSZLeXXbXppXa-170-62.png' ) ->send(); var_dump($result);

Advanced Usage

Custom Guzzle client

Replace the Guzzle client

<? php use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use GuzzleHttp\Handler\CurlHandler; use DingTalkRobot\DingTalkRobot; $robot = new DingTalkRobot(['access_token' => 'access_token_string', 'secret' => 'secret_string',]); $Handler = new CurlHandler(); $Handler = new CurlHandler(); $stack = HandlerStack::create($handler); $customClient = new Client(['handler' => $stack]); $message = $robot->message-> sethttpClient ($customClient); $result = $message->text ->setTextContent(' 156xxxx8827') -> addatMobile ('156xxxx8827') ->send();

Configure the Guzzle client

<? php use GuzzleHttp\HandlerStack; use GuzzleHttp\Handler\CurlHandler; use DingTalkRobot\DingTalkRobot; $Handler = new CurlHandler(); $Handler = new CurlHandler(); $stack = HandlerStack::create($handler); // instantiate; $robot = new dingTalkRobot (['access_token' => 'access_token_string', $robot = new dingTalkRobot (['access_token' => 'access_token_string', 'secret' => 'secret_string', 'guzzle_options' => ['handler' => $stack, // custom handler' timeout' => 10.0, // Set request timeout [,]); $result = $robot->message-> text-> setTextContent(' 156xxxx8827') -> addatMobile ('156xxxx8827') ->send();

Theoretically support coroutines by replacing the Guzzle client or configuring the Handler above has not been tested.

For more guzzle configurations see: guzzle Documentation

License

MIT