WeCallService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\service;
  15. /**
  16. * 网易云商智能外呼service
  17. * Class WeCallService
  18. * @package app\adminapi\service
  19. */
  20. class WeCallService
  21. {
  22. /**
  23. * 生成sign签名
  24. * @param $requestQuery GET请求时的url参数数组
  25. * @param $requestBody POST请求时的body参数Json字符串
  26. * @param $timestamp 时间戳(毫秒级)
  27. * @return string
  28. */
  29. public function getSign($requestQuery,$requestBody,$timestamp) {
  30. $appKey = "6143f9037f8546f6b83be0498dc19258";
  31. $appSecret = "cd1a1ec8089342a7a913b726013974c7";
  32. // 拼接值
  33. $queryStr = "";
  34. ksort($requestQuery);
  35. foreach($requestQuery as $value) {
  36. $queryStr .= $value;
  37. }
  38. // 得到签名值
  39. $needSign = $timestamp. $queryStr. $requestBody;
  40. $sign = hash_hmac('sha256', $needSign, $appSecret);
  41. return $sign;
  42. }
  43. /**
  44. * 获取时间戳(毫秒级)
  45. */
  46. public function get_millisecond_timestamp() {
  47. $microtime = microtime(true);
  48. $timestamp = floor($microtime * 1000);
  49. return $timestamp;
  50. }
  51. public function importUser(){
  52. $requestBody = '{
  53. "taskId": 2462591,
  54. "removeRepeat": false,
  55. "encryptedPhone" : false,
  56. "customerList": [
  57. {
  58. "phone": "13661306041",
  59. "properties": {
  60. "订单号": "40191",
  61. "详细地址":"武汉市洪山区",
  62. "服务类型":"洗衣机维修",
  63. "客户手机号":"136613060441"
  64. }
  65. },
  66. {
  67. "phone": "13661306044",
  68. "properties": {
  69. "订单号": "40192",
  70. "详细地址":"武汉市洪山区",
  71. "服务类型":"洗衣机清洗",
  72. "客户手机号":"136613060444"
  73. }
  74. }
  75. ]
  76. }';
  77. $requestBody = json_decode($requestBody,true);
  78. $requestBody = json_encode($requestBody);
  79. $requestQuery = [];
  80. $timestamp = $this->get_millisecond_timestamp();
  81. $sign = $this->getSign($requestQuery,$requestBody,$timestamp);
  82. //请求导入客户信息接口
  83. $header = [
  84. 'Content-Type: application/json',
  85. 'X-YS-APIKEY: 6143f9037f8546f6b83be0498dc19258',
  86. 'X-YS-TIME: '.$timestamp,
  87. 'X-YS-SIGNATURE: '.$sign,
  88. ];
  89. $response = http_request('https://b.163.com/open/api/wecall/v1/task/importCustomer', $requestBody, $header);
  90. echo $sign."\r\n";
  91. echo $timestamp."\r\n";
  92. print_r($response);
  93. }
  94. }