diff --git a/api/controllers/wechat/Lichene.php b/api/controllers/wechat/Lichene.php
new file mode 100644
index 00000000..92451bed
--- /dev/null
+++ b/api/controllers/wechat/Lichene.php
@@ -0,0 +1,273 @@
+log_file = "wechat_{$target_class}.log";
+ }
+
+ public function index()
+ {
+ echo 'index';
+ }
+
+ /**
+ * Notes:企业微信接收事件
+ * https://liche-api-dev.xiaoyu.com/wechat/lichene/get_qymsg
+ * https://api.liche.cn/wechat/lichene/get_qymsg
+ * https://open.work.weixin.qq.com/wwopen/devtool/interface?doc_id=14961 测试回调模式
+ * Created on: 2022/3/23 17:23
+ * Created by: dengbw
+ */
+ public function get_qymsg()
+ {
+ $param = $this->input->get();
+ debug_log('
--->qymsg_param:' . json_encode($param), $this->log_file);
+ require_once(COMMPATH . '/third_party/WXqy/WXBizMsgCrypt.php');
+ $encodingAesKey = "CXUVlU9C7KsxzglxRiMlMsG2WSqM4EkFufDvgjkFciU";
+ $token = "CEoJkwUFP58KfZJ";
+ $corpId = "wwff2d727ce47d6852";
+
+ $sVerifyMsgSig = $param['msg_signature'];
+ $sVerifyTimeStamp = $param['timestamp'];
+ $sVerifyNonce = $param['nonce'];
+ $sVerifyEchoStr = $param['echostr'];
+ // 需要返回的明文
+ $sEchoStr = "";
+ $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
+ if ($sVerifyEchoStr) {//验证回调URL
+ $errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
+ debug_log('qymsg_errCode:' . $errCode, $this->log_file);
+ if ($errCode == 0) {
+ // 验证URL成功,将sEchoStr返回
+ debug_log('qymsg_sEchoStr:' . $sEchoStr . '&sEchoStrurldecode=' . urldecode($sEchoStr), $this->log_file);
+ echo urldecode($sEchoStr);
+ } else {
+ echo $errCode;
+ }
+ exit;
+ }
+// $sVerifyMsgSig = '08eb02c5d7fefaa29e2bd6a63acb8dfcc902ccf4';
+// $sVerifyTimeStamp = '1620713245';
+// $sVerifyNonce = '1620719758';
+ if ($_SERVER['REQUEST_METHOD'] == "POST") {
+ $sReqData = file_get_contents("php://input");
+ //$sReqData = "";
+ //$log = '---';
+ //if (is_array($sReqData)) $log = print_r($sReqData, true);
+ //debug_log('qymsg_sReqData:' . json_encode($log, JSON_UNESCAPED_UNICODE), $this->log_file);
+ $sMsg = ""; // 解析之后的明文
+ $errCode = $wxcpt->DecryptMsg($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sReqData, $sMsg);
+ debug_log('qymsg_errCode:' . $errCode, $this->log_file);
+ if ($errCode == 0) {
+ $this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
+ $re_msg = (array)simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA);//xml转json
+ $ExternalUserID = $re_msg['ExternalUserID'];
+ $ChangeType = $re_msg['ChangeType'];
+ debug_log('qymsg_ChangeType:' . $ChangeType, $this->log_file);
+ $this->load->library('wx_qyapi', ['app' => 'lichene']);
+ if ($ChangeType == 'add_external_contact') {//添加企业客户事件
+ $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $ExternalUserID));
+ //debug_log('qymsg_external_errcode:' . $re['errcode'] . '&external_userid=' . $re['external_contact']['external_userid'], $this->log_file);
+ if ($re['errcode'] == 0) {
+ $external_userid = $re['external_contact']['external_userid'];
+ if ($external_userid) {
+ $re_qy = $this->mdWechatqy->get(array('external_userid' => $external_userid));
+ $jsondata['external_contact'] = $re['external_contact'] ? $re['external_contact'] : '';
+ $jsondata['follow_user'] = $re['follow_user'] ? $re['follow_user'] : '';
+ $tags_ary = $re['follow_user'][0]['tags'];
+ $tags = '';
+ if ($tags_ary && $tags_ary != '[]' && is_array($tags_ary)) {
+ $tags = implode(',', array_column($tags_ary, 'tag_id'));
+ }
+ $addData = array(
+ 'external_userid' => $re['external_contact']['external_userid'],
+ 'name' => $re['external_contact']['name'],
+ 'avatar' => $re['external_contact']['avatar'],
+ 'unionid' => $re['external_contact']['unionid'] ? $re['external_contact']['unionid'] : '',
+ 'userid' => $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '',
+ 'remark' => $re['follow_user'][0]['remark'] ? $re['follow_user'][0]['remark'] : '',
+ 'tags' => $tags,
+ 'c_time' => $re['follow_user'][0]['createtime'] ? $re['follow_user'][0]['createtime'] : time(),
+ 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
+ 'status' => 1,
+ );
+ if (!$re_qy) {
+ $this->mdWechatqy->add($addData);
+ } else {
+ $this->mdWechatqy->update($addData, array('external_userid' => $external_userid));
+ }
+ //debug_log('qymsg_addData:' . json_encode($addData, JSON_UNESCAPED_UNICODE), $this->log_file);
+ }
+ }
+ debug_log('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE), $this->log_file);
+ } else if ($ChangeType == 'update') {//修改企业客户事件
+ debug_log('qymsg_sMsg:' . json_encode($re_msg, JSON_UNESCAPED_UNICODE), $this->log_file);
+// $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $ExternalUserID));
+// debug_log('qymsg_external_errcode:' . $re['errcode'] . '&external_userid=' . $re['external_contact']['external_userid'], $this->log_file);
+// debug_log('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE), $this->log_file);
+ } else if ($ChangeType == 'del_follow_user') {//删除企业客户事件
+ if ($ExternalUserID) {
+ $re_qy = $this->mdWechatqy->get(array('external_userid' => $ExternalUserID));
+ if ($re_qy) {
+ $this->mdWechatqy->update(array('status' => -1), array('id' => $re_qy['id']));
+ }
+ }
+ }
+ //debug_log('qymsg_sMsg:' . json_encode($re_msg, JSON_UNESCAPED_UNICODE), $this->log_file);
+ }
+ }
+ }
+
+ /**
+ * Notes:临时更新用户客户id
+ * Created on: 2021/03/01 17:02
+ * Created by: dengbw
+ * https://liche-api-dev.xiaoyu.com/wechat/lichene/tem_external_contact
+ * https://api.liche.cn/wechat/lichene/tem_external_contact
+ */
+ public function tem_external_contact()
+ {
+ $this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
+ $this->load->library('wx_qyapi', ['app' => 'lichene']);
+ $param = $this->input->get();
+ $param['page'] = intval($param['page']);
+ //获取配置了客户联系功能的成员列表
+ $re = $this->wx_qyapi->get_external_contact(array('url' => 'get_follow_user_list'));
+ echo json_encode($re, JSON_UNESCAPED_UNICODE);
+ exit;
+ //用户分页分别获取避免超时
+// $userid = "DianCheDaRenXiaoLi";
+// if ($param['next_cursor'] || !$param['page']) {
+// $next_cursor = $this->get_by_user($userid, $param['next_cursor']);
+// header('refresh:3;url=/wechat/liche/tem_external_contact?next_cursor=' . $next_cursor . '&page=' . ($param['page'] + 1));
+// } else {
+// echo '跑数据结束=' . $userid;
+// }
+// exit;
+// ob_start(); //打开缓冲区
+ $follow_user = ["LinZhenZhen", "18950116819", "ShengHuaXiangXueTieLongLuPeng", "ChenHuiCan", "13600972070", "0fun",
+ "WuHuanZheng", "ChenWeiHua", "13313999284", "FuZhouShengHuaTaiQiCheXiaoShouYo", "DianCheDaRenXiaoLi", "YeJiaChen",
+ "LuoJinYan", "QianJianLin", "18005933510", "wudz", "huangy", "LiZhengHui", "YeRongZhang", "LiZhiWei", "CaiYaFen",
+ "TaoQianQian", "FanHaiYu", "XuDanPing", "ChenWenZhang", "HongXinYi", "CaiZhiMin", "JiangYeLei", "ZengLingYan", "18906027570",
+ "jean", "fuyy", "taric", "jimmy", "HongSiZe", "huangjq", "xugy", "wuhl", "HuangZhiJie", "ZhangShanBang", "zhangtf", "fudw",
+ "HuJianPing", "13666060496", "LinXiaoLong", "LinCongCong", "liuch", "RenLin", "18876491999", "KangPengHui", "liusb", "luohj",
+ "YangYaQi", "WangJiangFu", "SuiYuErAn", "Xia", "MuZi2020", "a.bing", "ChenZhiShen", "ChenCuiYun", "YuTing", "WenYan", "YueYouYin",
+ "QuanZhouLiCheChuNa"];
+ $count = count($follow_user);
+ if ($param['page'] >= $count) {
+ echo '
本次更新企业成员:';
+ echo '
成功更新 ' . $count . ' 人';
+ echo '
点击将再次更新企业成员>>>';
+ exit;
+ }
+ $userid = $follow_user[$param['page']];
+ $next_cursor = $this->get_by_user($userid, '');
+ if ($next_cursor) {
+ $ii = 0;
+ while ($next_cursor) {
+ $next_cursor = $this->get_by_user($userid, $next_cursor);
+ $ii++;
+ }
+ }
+ echo '
成功更新企业成员:' . $userid;
+ header('refresh:3;url=/wechat/liche/tem_external_contact?page=' . ($param['page'] + 1));
+ ob_end_flush();//输出全部内容到浏览器
+ }
+
+ private function get_by_user($userid = '', $next_cursor = '')
+ {
+ $re = $this->wx_qyapi->get_external_contact(array('url' => 'get_by_user', 'userid' => $userid, 'next_cursor' => $next_cursor, 'limit' => '100'));
+ $next_cursor = '';
+ if ($re['errcode'] == 0) {
+ $next_cursor = $re['next_cursor'];
+ foreach ($re['external_contact_list'] as $key => $value) {
+ $external_userid = $value['external_contact']['external_userid'];
+ if ($external_userid) {
+ $re_qy = $this->mdWechatqy->get(array('external_userid' => $external_userid));
+ $jsondata = array();
+ $jsondata['external_contact'] = $value['external_contact'] ? $value['external_contact'] : '';
+ $jsondata['follow_info'] = $value['follow_info'] ? $value['follow_info'] : '';
+ $tags = $value['follow_info']['tag_id'];
+ $addData = array(
+ 'external_userid' => $value['external_contact']['external_userid'],
+ 'name' => $value['external_contact']['name'],
+ 'avatar' => $value['external_contact']['avatar'],
+ 'unionid' => $value['external_contact']['unionid'] ? $value['external_contact']['unionid'] : '',
+ 'userid' => $value['follow_info']['userid'] ? $value['follow_info']['userid'] : '',
+ 'remark' => $value['follow_info']['remark'] ? $value['follow_info']['remark'] : '',
+ 'tags' => $tags && $tags != '[]' ? implode(',', $tags) : '',
+ 'c_time' => $value['follow_info']['createtime'] ? $value['follow_info']['createtime'] : time(),
+ 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
+ 'status' => 1,
+ );
+ if (!$re_qy) {
+ $this->mdWechatqy->add($addData);
+ } else {
+ $this->mdWechatqy->update($addData, array('external_userid' => $external_userid));
+ }
+ }
+ }
+ echo '
next_cursor=' . $next_cursor . '&external_contact_list=' . count($re['external_contact_list']);
+ }
+ return $next_cursor;
+ }
+
+ /**
+ * Notes:添加企业客户事件
+ * https://liche-api-dev.xiaoyu.com/wechat/lichene/add_wechatqy
+ * https://api.liche.cn/wechat/lichene/add_wechatqy
+ * Created on: 2021/5/14 17:23
+ * Created by: dengbw
+ */
+ public function add_wechatqy()
+ {
+ $param = $this->input->get();
+ $external_userid = $param['external_userid'];
+ if (!$external_userid) {
+ return false;
+ }
+ $this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
+ $this->load->library('wx_qyapi', ['app' => 'lichene']);
+ $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $external_userid));
+ print_r('qymsg_external_errcode:' . $re['errcode'] . '=' . $re['external_contact']['external_userid']);
+ if ($re['errcode'] == 0) {
+ $external_userid = $re['external_contact']['external_userid'];
+ if ($external_userid) {
+ $re_qy = $this->mdWechatqy->get(array('external_userid' => $external_userid));
+ $jsondata['external_contact'] = $re['external_contact'] ? $re['external_contact'] : '';
+ $jsondata['follow_user'] = $re['follow_user'] ? $re['follow_user'] : '';
+ $addData = array(
+ 'external_userid' => $re['external_contact']['external_userid'],
+ 'name' => $re['external_contact']['name'],
+ 'avatar' => $re['external_contact']['avatar'],
+ 'unionid' => $re['external_contact']['unionid'] ? $re['external_contact']['unionid'] : '',
+ 'userid' => $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '',
+ 'remark' => $re['follow_user'][0]['remark'] ? $re['follow_user'][0]['remark'] : '',
+ 'tags' => $re['follow_user'][0]['tags'] ? $re['follow_user'][0]['tags'] : '',
+ 'c_time' => $re['follow_user'][0]['createtime'] ? $re['follow_user'][0]['createtime'] : time(),
+ 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
+ 'status' => 1,
+ );
+ if (!$re_qy) {
+ $this->mdWechatqy->add($addData);
+ } else {
+ $this->mdWechatqy->update($addData, array('external_userid' => $external_userid));
+ }
+ print_r('qymsg_addData:' . json_encode($addData, JSON_UNESCAPED_UNICODE));
+ }
+ }
+ print_r('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE));
+ }
+
+}
diff --git a/api/controllers/wxapp/liche/Auto.php b/api/controllers/wxapp/liche/Auto.php
index 151048f7..a1ca6f33 100644
--- a/api/controllers/wxapp/liche/Auto.php
+++ b/api/controllers/wxapp/liche/Auto.php
@@ -31,7 +31,7 @@ class Auto extends Wxapp
$biz_id = intval($this->input_param('biz_id'));
$re = $this->mdAutoIntroduce->get(array('id' => $id, 'status' => 1));
if (!$re || empty($re)) {
- throw new Exception('车型介绍不存在', API_CODE_FAIL);
+ throw new Exception('车型介绍不存在!', API_CODE_FAIL);
}
if ($biz_id && $this->session['mobile']) {//加标签
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
@@ -69,7 +69,7 @@ class Auto extends Wxapp
$this->load->model('auto/auto_introduce_model', 'mdAutoIntroduce');
$re = $this->mdAutoIntroduce->get(array('id' => $id, 'status' => 1));
if (!$re || empty($re)) {
- throw new Exception('车型介绍不存在', API_CODE_SUCCESS);
+ throw new Exception('车型介绍不存在!', API_CODE_SUCCESS);
}
$re_biz = $this->mdBiz->get(['id' => $biz_id, 'status' => 1]);
if (!$re_biz) {
@@ -85,6 +85,8 @@ class Auto extends Wxapp
'cf_title' => '自有资源',
'of_id' => $of_id,
'p_time' => date('Y-m-d H:i:s'),
+ 'status' => 1,//到店客户
+ 'a_num' => 1,
'c_time' => time()
];
$where = ['biz_id' => $biz_id, 'mobile' => $add_data['mobile']];
@@ -94,7 +96,7 @@ class Auto extends Wxapp
}
$id = $this->mdCustomers->add($add_data);
if (!$id) {
- throw new Exception('预约报名失败!', API_CODE_SUCCESS);
+ throw new Exception('报名失败!', API_CODE_SUCCESS);
}
$this->addTag(['c_id' => $id, 'brand_id' => $re['brand_id']]);
throw new Exception('报名成功!', API_CODE_SUCCESS);
diff --git a/common/libraries/Wx_qyapi.php b/common/libraries/Wx_qyapi.php
index 8b5f7c66..9b379afb 100644
--- a/common/libraries/Wx_qyapi.php
+++ b/common/libraries/Wx_qyapi.php
@@ -43,10 +43,15 @@ class Wx_qyapi
function init($params)
{
$configs = array(
+ //狸车新能源
+ 'lichene' => array(
+ 'corpid' => 'wwff2d727ce47d6852',
+ 'corpsecret' => 'wXAdJr6WgMnN6myPC73gXyxyHWpqwiI7dDaN21OAWV0',
+ ),
//狸车
'liche' => array(
'corpid' => 'wwc2caba960d202087',//企业ID
- 'corpsecret' => 'aQ2yhOBTXZnM0iwFtBzYIWbtyq4wFaIXBYTKg3xFxas',//企业密钥 R9fj_ocdb5p4Vr_qaQY54A4Z5SbyZBRWk4nfTMiPxgo
+ 'corpsecret' => 'aQ2yhOBTXZnM0iwFtBzYIWbtyq4wFaIXBYTKg3xFxas',//企业密钥
),
//星选家
'xxj' => array(
diff --git a/common/models/app/App_lichene_qy_model.php b/common/models/app/App_lichene_qy_model.php
new file mode 100644
index 00000000..78d4214b
--- /dev/null
+++ b/common/models/app/App_lichene_qy_model.php
@@ -0,0 +1,17 @@
+table_name, 'default');
+ }
+}