Przeglądaj źródła

提交外呼任务

dongxiaoqin 1 rok temu
rodzic
commit
b5de5f55eb
1 zmienionych plików z 106 dodań i 0 usunięć
  1. 106 0
      app/adminapi/service/WeCallService.php

+ 106 - 0
app/adminapi/service/WeCallService.php

@@ -0,0 +1,106 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+
+namespace app\adminapi\service;
+
+
+
+/**
+ * 网易云商智能外呼service
+ * Class WeCallService
+ * @package app\adminapi\service
+ */
+class WeCallService
+{
+
+    /**
+     * 生成sign签名
+     * @param $requestQuery GET请求时的url参数数组
+     * @param $requestBody POST请求时的body参数Json字符串
+     * @param $timestamp 时间戳(毫秒级)
+     * @return string
+     */
+    public function getSign($requestQuery,$requestBody,$timestamp) {
+        $appKey = "6143f9037f8546f6b83be0498dc19258";
+        $appSecret = "cd1a1ec8089342a7a913b726013974c7";
+        
+        // 拼接值
+        $queryStr = "";
+        ksort($requestQuery);
+        foreach($requestQuery as $value) {
+            $queryStr .= $value;
+        }
+        
+        // 得到签名值
+        $needSign = $timestamp. $queryStr. $requestBody;
+        $sign = hash_hmac('sha256', $needSign, $appSecret);
+        return $sign;
+    }
+    /**
+     * 获取时间戳(毫秒级)
+     */
+    public function get_millisecond_timestamp() {
+        $microtime = microtime(true);
+        $timestamp = floor($microtime * 1000);
+        return $timestamp;
+    }
+
+    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);
+        $requestBody = json_encode($requestBody);
+        $requestQuery = [];
+        $timestamp = $this->get_millisecond_timestamp();
+        $sign = $this->getSign($requestQuery,$requestBody,$timestamp);
+
+
+        //请求导入客户信息接口
+        $header = [
+            'Content-Type: application/json',
+            'X-YS-APIKEY: 6143f9037f8546f6b83be0498dc19258',
+            'X-YS-TIME: '.$timestamp,
+            'X-YS-SIGNATURE: '.$sign,
+        ];
+        $response = http_request('https://b.163.com/open/api/wecall/v1/task/importCustomer', $requestBody, $header);
+
+        echo $sign."\r\n";
+        echo $timestamp."\r\n";
+        print_r($response);
+    }
+}