|
@@ -24,6 +24,19 @@ namespace app\adminapi\service;
|
|
|
*/
|
|
*/
|
|
|
class WeCallService
|
|
class WeCallService
|
|
|
{
|
|
{
|
|
|
|
|
+ protected $appKey;
|
|
|
|
|
+ protected $appSecret;
|
|
|
|
|
+ protected $taskId;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct()
|
|
|
|
|
+ {
|
|
|
|
|
+ $config = config('custom.wecall');
|
|
|
|
|
+ if ($config) {
|
|
|
|
|
+ $this->appKey = $config['appKey'];
|
|
|
|
|
+ $this->appSecret = $config['appSecret'];
|
|
|
|
|
+ $this->taskId = $config['taskId'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成sign签名
|
|
* 生成sign签名
|
|
@@ -32,10 +45,7 @@ class WeCallService
|
|
|
* @param $timestamp 时间戳(毫秒级)
|
|
* @param $timestamp 时间戳(毫秒级)
|
|
|
* @return string
|
|
* @return string
|
|
|
*/
|
|
*/
|
|
|
- public function getSign($requestQuery,$requestBody,$timestamp) {
|
|
|
|
|
- $appKey = "6143f9037f8546f6b83be0498dc19258";
|
|
|
|
|
- $appSecret = "cd1a1ec8089342a7a913b726013974c7";
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public function getSign($requestQuery,$requestBody,$timestamp) {
|
|
|
// 拼接值
|
|
// 拼接值
|
|
|
$queryStr = "";
|
|
$queryStr = "";
|
|
|
ksort($requestQuery);
|
|
ksort($requestQuery);
|
|
@@ -45,62 +55,116 @@ class WeCallService
|
|
|
|
|
|
|
|
// 得到签名值
|
|
// 得到签名值
|
|
|
$needSign = $timestamp. $queryStr. $requestBody;
|
|
$needSign = $timestamp. $queryStr. $requestBody;
|
|
|
- $sign = hash_hmac('sha256', $needSign, $appSecret);
|
|
|
|
|
|
|
+ $sign = hash_hmac('sha256', $needSign, $this->appSecret);
|
|
|
return $sign;
|
|
return $sign;
|
|
|
}
|
|
}
|
|
|
- /**
|
|
|
|
|
- * 获取时间戳(毫秒级)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 向外呼任务导入客户
|
|
|
*/
|
|
*/
|
|
|
- public function get_millisecond_timestamp() {
|
|
|
|
|
- $microtime = microtime(true);
|
|
|
|
|
- $timestamp = floor($microtime * 1000);
|
|
|
|
|
- return $timestamp;
|
|
|
|
|
|
|
+ public function importUser($customerList){
|
|
|
|
|
+ if (empty($this->appKey) || empty($this->appSecret) || empty($this->taskId)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $requestBody = [
|
|
|
|
|
+ 'taskId' => $this->taskId,
|
|
|
|
|
+ 'removeRepeat' => false,
|
|
|
|
|
+ 'encryptedPhone' => false,
|
|
|
|
|
+ 'customerList' => $customerList
|
|
|
|
|
+ ];
|
|
|
|
|
+ $requestBody = json_encode($requestBody);
|
|
|
|
|
+ $timestamp = $this->get_millisecond_timestamp();
|
|
|
|
|
+ $sign = $this->getSign([],$requestBody,$timestamp);
|
|
|
|
|
+
|
|
|
|
|
+ //请求导入客户信息接口
|
|
|
|
|
+ $header = [
|
|
|
|
|
+ 'Content-Type: application/json',
|
|
|
|
|
+ 'X-YS-APIKEY: '.$this->appKey,
|
|
|
|
|
+ 'X-YS-TIME: '.$timestamp,
|
|
|
|
|
+ 'X-YS-SIGNATURE: '.$sign,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $response = http_request('https://b.163.com/open/api/wecall/v1/task/importCustomer', $requestBody, $header);
|
|
|
|
|
+ return $response;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function importUser(){
|
|
|
|
|
- $requestBody = '{
|
|
|
|
|
- "taskId": 2462591,
|
|
|
|
|
- "removeRepeat": false,
|
|
|
|
|
- "encryptedPhone" : false,
|
|
|
|
|
- "customerList": [
|
|
|
|
|
- {
|
|
|
|
|
- "phone": "13661306041",
|
|
|
|
|
- "properties": {
|
|
|
|
|
- "订单号": "40191",
|
|
|
|
|
- "详细地址":"武汉市洪山区",
|
|
|
|
|
- "服务类型":"洗衣机维修",
|
|
|
|
|
- "客户手机号":"136613060441"
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- "phone": "13661306044",
|
|
|
|
|
- "properties": {
|
|
|
|
|
- "订单号": "40192",
|
|
|
|
|
- "详细地址":"武汉市洪山区",
|
|
|
|
|
- "服务类型":"洗衣机清洗",
|
|
|
|
|
- "客户手机号":"136613060444"
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- }';
|
|
|
|
|
- $requestBody = json_decode($requestBody,true);
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 开启外呼任务(仅手动任务可调用)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function startTask(){
|
|
|
|
|
+ if (empty($this->appKey) || empty($this->appSecret) || empty($this->taskId)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $requestBody = [
|
|
|
|
|
+ 'taskId' => $this->taskId
|
|
|
|
|
+ ];
|
|
|
$requestBody = json_encode($requestBody);
|
|
$requestBody = json_encode($requestBody);
|
|
|
- $requestQuery = [];
|
|
|
|
|
$timestamp = $this->get_millisecond_timestamp();
|
|
$timestamp = $this->get_millisecond_timestamp();
|
|
|
- $sign = $this->getSign($requestQuery,$requestBody,$timestamp);
|
|
|
|
|
|
|
+ $sign = $this->getSign([],$requestBody,$timestamp);
|
|
|
|
|
+
|
|
|
|
|
+ //请求导入客户信息接口
|
|
|
|
|
+ $header = [
|
|
|
|
|
+ 'Content-Type: application/json',
|
|
|
|
|
+ 'X-YS-APIKEY: '.$this->appKey,
|
|
|
|
|
+ 'X-YS-TIME: '.$timestamp,
|
|
|
|
|
+ 'X-YS-SIGNATURE: '.$sign,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $response = http_request('https://b.163.com/open/api/wecall/v1/task/start', $requestBody, $header);
|
|
|
|
|
+ return $response;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 停止外呼任务(仅手动任务可调用)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function stopTask(){
|
|
|
|
|
+ if (empty($this->appKey) || empty($this->appSecret) || empty($this->taskId)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $requestBody = [
|
|
|
|
|
+ 'taskId' => $this->taskId
|
|
|
|
|
+ ];
|
|
|
|
|
+ $requestBody = json_encode($requestBody);
|
|
|
|
|
+ $timestamp = $this->get_millisecond_timestamp();
|
|
|
|
|
+ $sign = $this->getSign([],$requestBody,$timestamp);
|
|
|
|
|
|
|
|
//请求导入客户信息接口
|
|
//请求导入客户信息接口
|
|
|
$header = [
|
|
$header = [
|
|
|
'Content-Type: application/json',
|
|
'Content-Type: application/json',
|
|
|
- 'X-YS-APIKEY: 6143f9037f8546f6b83be0498dc19258',
|
|
|
|
|
|
|
+ 'X-YS-APIKEY: '.$this->appKey,
|
|
|
'X-YS-TIME: '.$timestamp,
|
|
'X-YS-TIME: '.$timestamp,
|
|
|
'X-YS-SIGNATURE: '.$sign,
|
|
'X-YS-SIGNATURE: '.$sign,
|
|
|
];
|
|
];
|
|
|
- $response = http_request('https://b.163.com/open/api/wecall/v1/task/importCustomer', $requestBody, $header);
|
|
|
|
|
|
|
+ $response = http_request('https://b.163.com/open/api/wecall/v1/task/stop', $requestBody, $header);
|
|
|
|
|
+ return $response;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- echo $sign."\r\n";
|
|
|
|
|
- echo $timestamp."\r\n";
|
|
|
|
|
- print_r($response);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 数据回调接口
|
|
|
|
|
+ */
|
|
|
|
|
+ public function notify($body) {
|
|
|
|
|
+ $body = json_decode($body, true);
|
|
|
|
|
+ if ($body && isset($body['dataType'])) {
|
|
|
|
|
+ if ($body['dataType'] == 'ROBOT_TASK_STATUS_CHANGE') {
|
|
|
|
|
+ $this->taskStatusChange($body['data']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function taskStatusChange($data)
|
|
|
|
|
+ {
|
|
|
|
|
+ $taskId = $data['taskId'];
|
|
|
|
|
+ $status = $data['status'];
|
|
|
|
|
+ $updateTime = $data['updateTime'];
|
|
|
|
|
+ if ($taskId == $this->taskId && $status == 'COMPLETE') {
|
|
|
|
|
+ // TODO 任务状态改变
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取时间戳(毫秒级)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function get_millisecond_timestamp() {
|
|
|
|
|
+ $microtime = microtime(true);
|
|
|
|
|
+ $timestamp = floor($microtime * 1000);
|
|
|
|
|
+ return $timestamp;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|