persona_320
persona_320_2
This commit is contained in:
+77
-10
@@ -6,7 +6,8 @@
|
||||
* Date: 2020/9/14
|
||||
* Time: 10:51
|
||||
*/
|
||||
class Weixin extends CI_Controller{
|
||||
class Weixin extends CI_Controller
|
||||
{
|
||||
private $app_id;
|
||||
private $reset;
|
||||
private $appid;
|
||||
@@ -14,7 +15,8 @@ class Weixin extends CI_Controller{
|
||||
private $corpid;
|
||||
private $corpsecret;
|
||||
|
||||
public function __construct(){
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->app_id = $this->input->get('app_id');
|
||||
@@ -30,7 +32,7 @@ class Weixin extends CI_Controller{
|
||||
);
|
||||
|
||||
$wx_config = $wx_configs[$this->app_id];
|
||||
if($wx_config){
|
||||
if ($wx_config) {
|
||||
!$this->appid && $this->appid = $wx_config['appid'];
|
||||
!$this->secret && $this->secret = $wx_config['secret'];
|
||||
}
|
||||
@@ -42,7 +44,8 @@ class Weixin extends CI_Controller{
|
||||
/**
|
||||
* 获取access_token
|
||||
*/
|
||||
function access_token(){
|
||||
function access_token()
|
||||
{
|
||||
$access_token = $this->hd_wechat->access_token($this->reset);
|
||||
|
||||
$data = array("access_token" => $access_token);
|
||||
@@ -55,7 +58,8 @@ class Weixin extends CI_Controller{
|
||||
/**
|
||||
* 获取分享凭证
|
||||
*/
|
||||
function api_ticket(){
|
||||
function api_ticket()
|
||||
{
|
||||
$api_ticket = $this->hd_wechat->api_ticket($this->reset);
|
||||
|
||||
$data = array("api_ticket" => $api_ticket);
|
||||
@@ -63,24 +67,87 @@ class Weixin extends CI_Controller{
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 企业微信access_token
|
||||
*/
|
||||
public function qy_access_token(){
|
||||
public function qy_access_token()
|
||||
{
|
||||
$app = $this->input->get('app');
|
||||
$corpid = $this->input->get('corpid');
|
||||
$corpsecret = $this->input->get('corpsecret');
|
||||
|
||||
$params = array();
|
||||
$app && $params['app'] = $app;
|
||||
$corpid && $params['corpid'] = $corpid;
|
||||
$corpsecret && $params['corpsecret'] = $corpsecret;
|
||||
|
||||
$this->load->library('wx_qyapi', $params);
|
||||
$access_token = $this->wx_qyapi->access_token();
|
||||
|
||||
$data['access_token'] = $access_token;
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:企业微信ticket
|
||||
* Created on: 2022/3/30 9:53
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function qy_jsapi_ticket()
|
||||
{
|
||||
$app = $this->input->get('app');
|
||||
$corpid = $this->input->get('corpid');
|
||||
$corpsecret = $this->input->get('corpsecret');
|
||||
$params = array();
|
||||
$app && $params['app'] = $app;
|
||||
$corpid && $params['corpid'] = $corpid;
|
||||
$corpsecret && $params['corpsecret'] = $corpsecret;
|
||||
$this->load->library('wx_qyapi', $params);
|
||||
$ticket = $this->wx_qyapi->jsapi_ticket();
|
||||
$data['ticket'] = $ticket;
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:企业微信自建应用access_token
|
||||
* Created on: 2022/3/30 9:57
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function qy_agent_access_token()
|
||||
{
|
||||
$app = $this->input->get('app');
|
||||
$corpid = $this->input->get('corpid');
|
||||
$corpsecret = $this->input->get('corpsecret');
|
||||
$params = array();
|
||||
$app && $params['app'] = $app;
|
||||
$corpid && $params['corpid'] = $corpid;
|
||||
$corpsecret && $params['corpsecret'] = $corpsecret;
|
||||
$this->load->library('wx_qyapi_agent', $params);
|
||||
$access_token = $this->wx_qyapi_agent->access_token();
|
||||
$data['access_token'] = $access_token;
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:企业微信自建应用ticket
|
||||
* Created on: 2022/3/30 9:53
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function qy_agent_jsapi_ticket()
|
||||
{
|
||||
$app = $this->input->get('app');
|
||||
$corpid = $this->input->get('corpid');
|
||||
$corpsecret = $this->input->get('corpsecret');
|
||||
$params = array();
|
||||
$app && $params['app'] = $app;
|
||||
$corpid && $params['corpid'] = $corpid;
|
||||
$corpsecret && $params['corpsecret'] = $corpsecret;
|
||||
$this->load->library('wx_qyapi_agent', $params);
|
||||
$ticket = $this->wx_qyapi_agent->jsapi_ticket();
|
||||
$data['ticket'] = $ticket;
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,11 +32,9 @@ class Wx_qyapi
|
||||
} else { // 正式
|
||||
$this->env = 'p';
|
||||
}
|
||||
|
||||
$this->redis = &load_cache('redis');
|
||||
$this->ci = &get_instance();
|
||||
$this->ci->load->library('mycurl');
|
||||
|
||||
$this->init($params);
|
||||
}
|
||||
|
||||
@@ -53,32 +51,23 @@ class Wx_qyapi
|
||||
'corpid' => 'wwc2caba960d202087',//企业ID
|
||||
'corpsecret' => 'aQ2yhOBTXZnM0iwFtBzYIWbtyq4wFaIXBYTKg3xFxas',//企业密钥
|
||||
),
|
||||
//星选家
|
||||
'xxj' => array(
|
||||
'corpid' => 'wwecac3c2b60c31b1b',//企业ID
|
||||
'corpsecret' => 'EFIev4j-0iv4Uy2vrDATzsL3aIW2IT_kRO4zx73I31g',//企业密钥 R9fj_ocdb5p4Vr_qaQY54A4Z5SbyZBRWk4nfTMiPxgo
|
||||
),
|
||||
//福建小鱼
|
||||
'fjxy' => array(
|
||||
'corpid' => 'wweeb9c2f4fbb2227b',//企业ID
|
||||
'corpsecret' => 'SWgWz7TAyLWm6SKvI3uPZ5c5-ZjS0GIxS7kf92rhIwA',//企业密钥
|
||||
'coragent' => array('1000012'),//企业应用:号码隐藏功能
|
||||
),
|
||||
);
|
||||
|
||||
$params['corpid'] && $this->corpid = $params['corpid'];
|
||||
$params['corpsecret'] && $this->corpsecret = $params['corpsecret'];
|
||||
|
||||
$app = $params['app'] ? $params['app'] : 'liche';
|
||||
if ($configs[$app]) {
|
||||
$config = $configs[$app];
|
||||
!$this->corpid && $config['corpid'] && $this->corpid = $config['corpid'];
|
||||
!$this->corpsecret && $config['corpsecret'] && $this->corpsecret = $config['corpsecret'];
|
||||
}
|
||||
|
||||
$this->corpid && $this->log_file = "wx_qyapi_{$this->corpid}.log";
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return ['corpid' => $this->corpid, 'corpsecret' => $this->corpsecret];
|
||||
}
|
||||
|
||||
public function access_token()
|
||||
{
|
||||
$access_token = $this->redis->get($this->corpsecret);
|
||||
@@ -94,7 +83,7 @@ class Wx_qyapi
|
||||
$this->redis->save($this->corpsecret, $result->access_token, $result->expires_in);
|
||||
}
|
||||
} else {
|
||||
$url = "https://api.haodian.cn/weixin/qy_access_token?corpid={$this->corpid}&corpsecret={$this->corpsecret}";
|
||||
$url = "https://api.liche.cn/weixin/qy_access_token?corpid={$this->corpid}&corpsecret={$this->corpsecret}";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
$access_token = $result->access_token;
|
||||
@@ -177,7 +166,7 @@ class Wx_qyapi
|
||||
|
||||
public function getSignPackage()
|
||||
{
|
||||
$jsapiTicket = $this->getJsApiTicket();
|
||||
$jsapiTicket = $this->jsapi_ticket();
|
||||
$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
||||
$timestamp = time();
|
||||
$nonceStr = $this->createNonceStr();
|
||||
@@ -198,25 +187,31 @@ class Wx_qyapi
|
||||
return $signPackage;
|
||||
}
|
||||
|
||||
public function getJsApiTicket()
|
||||
public function jsapi_ticket()
|
||||
{
|
||||
$key = 'jsapi_ticket_' . $this->corpsecret;
|
||||
$jsapi_ticket = $this->redis->get($key);
|
||||
if (!$jsapi_ticket) {
|
||||
//获取企业的jsapi_ticket https://developer.work.weixin.qq.com/document/path/90506#14924
|
||||
//https://developer.work.weixin.qq.com/document/10029#%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi_ticket
|
||||
$access_token = $this->access_token();
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={$access_token}";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
if ($result->errcode) {
|
||||
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
|
||||
$key = 'ticket_' . $this->corpsecret;
|
||||
$ticket = $this->redis->get($key);
|
||||
if (!$ticket) {
|
||||
if ($this->env == 'p') {
|
||||
//获取企业的jsapi_ticket https://developer.work.weixin.qq.com/document/path/90506#14924
|
||||
$access_token = $this->access_token();
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={$access_token}";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
if ($result->errcode) {
|
||||
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
|
||||
} else {
|
||||
$ticket = $result->ticket;
|
||||
$this->redis->save($key, $result->ticket, $result->expires_in);
|
||||
}
|
||||
} else {
|
||||
$jsapi_ticket = $result->ticket;
|
||||
$this->redis->save($key, $result->ticket, $result->expires_in);
|
||||
$url = "https://api.liche.cn/weixin/qy_jsapi_ticket?corpid={$this->corpid}&corpsecret={$this->corpsecret}";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
$ticket = $result->ticket;
|
||||
}
|
||||
}
|
||||
return $jsapi_ticket;
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
private function createNonceStr($length = 16)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Vim
|
||||
* User: Lcc
|
||||
* Date: 2020-12-25
|
||||
* Time: 10:23
|
||||
* Desc: 企业微信api
|
||||
* Notes:企业微信自建应用api
|
||||
* Created on: 2022/3/29 10:34
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Wx_qyapi_agent
|
||||
{
|
||||
const BASE_URL = 'https://qyapi.weixin.qq.com/';
|
||||
const TOKEN_API = 'cgi-bin/gettoken?corpid=%s&corpsecret=%s'; //获取access_token
|
||||
|
||||
private $redis;
|
||||
private $corpid;
|
||||
private $corpsecret;
|
||||
@@ -34,7 +31,6 @@ class Wx_qyapi_agent
|
||||
$this->redis = &load_cache('redis');
|
||||
$this->ci = &get_instance();
|
||||
$this->ci->load->library('mycurl');
|
||||
|
||||
$this->init($params);
|
||||
}
|
||||
|
||||
@@ -71,22 +67,34 @@ class Wx_qyapi_agent
|
||||
{
|
||||
$access_token = $this->redis->get($this->corpsecret);
|
||||
if (!$access_token) {
|
||||
$url = self::BASE_URL . sprintf(self::TOKEN_API, $this->corpid, $this->corpsecret);
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
if ($result->errcode) {
|
||||
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
|
||||
if ($this->env == 'p') {
|
||||
$url = self::BASE_URL . sprintf(self::TOKEN_API, $this->corpid, $this->corpsecret);
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
if ($result->errcode) {
|
||||
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
|
||||
} else {
|
||||
$access_token = $result->access_token;
|
||||
$this->redis->save($this->corpsecret, $result->access_token, $result->expires_in);
|
||||
}
|
||||
} else {
|
||||
$url = "https://api.liche.cn/weixin/qy_agent_access_token?corpid={$this->corpid}&corpsecret={$this->corpsecret}";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
$access_token = $result->access_token;
|
||||
$this->redis->save($this->corpsecret, $result->access_token, $result->expires_in);
|
||||
}
|
||||
}
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return ['corpid' => $this->corpid, 'corpsecret' => $this->corpsecret, 'agentid' => $this->agentid];
|
||||
}
|
||||
|
||||
public function getSignPackage()
|
||||
{
|
||||
$jsapiTicket = $this->getJsApiTicket();
|
||||
$jsapiTicket = $this->jsapi_ticket();
|
||||
$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
||||
$timestamp = time();
|
||||
$nonceStr = $this->createNonceStr();
|
||||
@@ -108,24 +116,31 @@ class Wx_qyapi_agent
|
||||
return $signPackage;
|
||||
}
|
||||
|
||||
public function getJsApiTicket()
|
||||
public function jsapi_ticket()
|
||||
{
|
||||
$key = 'jsapi_ticket_' . $this->corpsecret;
|
||||
$jsapi_ticket = $this->redis->get($key);
|
||||
if (!$jsapi_ticket) {
|
||||
//https://developer.work.weixin.qq.com/document/10029#%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi_ticket
|
||||
$access_token = $this->access_token();
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token={$access_token}&type=agent_config";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
if ($result->errcode) {
|
||||
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
|
||||
$key = 'ticket_' . $this->corpsecret;
|
||||
$ticket = $this->redis->get($key);
|
||||
if (!$ticket) {
|
||||
if ($this->env == 'p') {
|
||||
//获取企业应用jsapi_ticket 的https://developer.work.weixin.qq.com/document/10029#%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi_ticket
|
||||
$access_token = $this->access_token();
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token={$access_token}&type=agent_config";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
if ($result->errcode) {
|
||||
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
|
||||
} else {
|
||||
$ticket = $result->ticket;
|
||||
$this->redis->save($key, $result->ticket, $result->expires_in);
|
||||
}
|
||||
} else {
|
||||
$jsapi_ticket = $result->ticket;
|
||||
$this->redis->save($key, $result->ticket, $result->expires_in);
|
||||
$url = "https://api.liche.cn/weixin/qy_agent_jsapi_ticket?corpid={$this->corpid}&corpsecret={$this->corpsecret}";
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
$ticket = $result->ticket;
|
||||
}
|
||||
}
|
||||
return $jsapi_ticket;
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
private function createNonceStr($length = 16)
|
||||
|
||||
@@ -8,31 +8,54 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
*/
|
||||
class Persona extends CI_Controller
|
||||
{
|
||||
private $config_qyapi;
|
||||
private $config_qyapi_agent;
|
||||
private $log_file;
|
||||
private $aid;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$target_class = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称
|
||||
$this->log_file = "home_h5_{$target_class}.log";
|
||||
$aid = $this->input->get('aid') ? $this->input->get('aid') : $this->input->post('aid');
|
||||
$this->aid = intval($aid);
|
||||
if ($this->aid == 1) {
|
||||
$this->config_qyapi = ['app' => 'liche'];
|
||||
$this->config_qyapi_agent = ['app' => 'liche_1000024'];
|
||||
} else {
|
||||
$this->config_qyapi = ['app' => 'lichene'];
|
||||
$this->config_qyapi_agent = ['app' => 'lichene_1000005'];
|
||||
}
|
||||
$this->load->library('wx_qyapi', $this->config_qyapi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:客户画像
|
||||
* https://liche-dev.xiaoyu.com/h5/lichene
|
||||
* https://www.liche.cn/h5/lichene
|
||||
* https://liche-dev.xiaoyu.com/h5/persona
|
||||
* https://www.liche.cn/h5/persona
|
||||
* Created on: 2022/3/25 11:19
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->load->library('wx_qyapi', ['app' => 'lichene']);
|
||||
$this->load->library('wx_qyapi_agent', $this->config_qyapi_agent);
|
||||
$params = $this->input->get();
|
||||
$url = http_host_com('home') . "/h5/persona?aid={$params['aid']}";
|
||||
$result = $this->set_auth($url, $params);
|
||||
$user_id = 0;
|
||||
if ($result['errcode'] == 0 && $result['UserId']) {//获取企业员工userid
|
||||
$user_id = $result['UserId'];
|
||||
}
|
||||
//echo 'user_id=' . $result['UserId'] . '&aid=' . $this->aid;
|
||||
$sign_package = $this->wx_qyapi->getSignPackage();
|
||||
|
||||
$this->load->library('wx_qyapi_agent');
|
||||
$sign_package2 = $this->wx_qyapi_agent->getSignPackage();
|
||||
$sign_package2['agentid'] = '1000005';
|
||||
//echo json_encode($sign_package, JSON_UNESCAPED_UNICODE);
|
||||
//echo '<br><br>';
|
||||
//echo json_encode($sign_package2, JSON_UNESCAPED_UNICODE);
|
||||
$data = ['_title' => '客户画像', 'sign_package' => $sign_package, 'sign_package2' => $sign_package2];
|
||||
$this->load->view('/h5/lichene/index', $data);
|
||||
$sign_package_agent = $this->wx_qyapi_agent->getSignPackage();
|
||||
// echo json_encode($sign_package, JSON_UNESCAPED_UNICODE);
|
||||
// echo '<br><br>';
|
||||
// echo json_encode($sign_package_agent, JSON_UNESCAPED_UNICODE);
|
||||
$data = ['_title' => '客户画像', 'sign_package' => $sign_package, 'sign_package_agent' => $sign_package_agent
|
||||
, 'user_id' => $user_id, 'aid' => $this->aid];
|
||||
$this->load->view('/h5/persona/index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,13 +77,24 @@ class Persona extends CI_Controller
|
||||
$this->show_json(400, '加载失败请重试~');
|
||||
}
|
||||
if ($params['external_userid']) {
|
||||
$this->load->library('wx_qyapi', ['app' => 'lichene']);
|
||||
//$this->load->library('wx_qyapi', $this->config_qyapi);
|
||||
//外部联系人
|
||||
$re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $params['external_userid']));
|
||||
//debug_log('externalcontact_get:' . json_encode($re, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
if (!$re) {
|
||||
$this->show_json(400, '加载失败请重试!');
|
||||
}
|
||||
$tags_ary = $re['follow_user'][0]['tags'];//客户画像
|
||||
$follow_user = [];
|
||||
foreach ($re['follow_user'] as $key => $val) {
|
||||
if ($val['userid'] == $params['user_id']) {//找出当前企业员工
|
||||
$follow_user = $val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$tags_ary = $follow_user['tags'];//客户画像
|
||||
$userid = $follow_user['userid'];
|
||||
$remark_mobiles = $follow_user['remark_mobiles'];//用户手机
|
||||
$description = $follow_user['description'];//描述
|
||||
if ($tags_ary && $tags_ary != '[]' && is_array($tags_ary)) {
|
||||
foreach ($tags_ary as $key => $val) {
|
||||
if ($val['type'] == 1) {//企业标签
|
||||
@@ -69,11 +103,8 @@ class Persona extends CI_Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
$userid = $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '';
|
||||
$avatar = $mobile = $name = $unionid = '';
|
||||
$gender = $biz_id = 0;
|
||||
$remark_mobiles = $re['follow_user'][0]['remark_mobiles'];//用户手机
|
||||
$description = $re['follow_user'][0]['description'];//描述
|
||||
if ($remark_mobiles && $remark_mobiles != '[]' && is_array($remark_mobiles)) {
|
||||
$mobile = $remark_mobiles[0];//取第一个手机号
|
||||
}
|
||||
@@ -266,7 +297,7 @@ class Persona extends CI_Controller
|
||||
}
|
||||
}
|
||||
if (!$re_cus) {//新增客户 更新企微信息
|
||||
$this->load->library('wx_qyapi', ['app' => 'lichene']);
|
||||
//$this->load->library('wx_qyapi', $this->config_qyapi);
|
||||
$remark_mobiles = $userInfo['mobile'] ? [$userInfo['mobile']] : '';
|
||||
$description = $params['of_title'] ? $params['of_title'] : '';
|
||||
if ($description && $params['of2_title']) {
|
||||
@@ -293,8 +324,10 @@ class Persona extends CI_Controller
|
||||
}
|
||||
}
|
||||
//企微标签操作
|
||||
$this->wx_qyapi->get_external_contact(['url' => 'mark_tag', 'userid' => $userInfo['userid'],
|
||||
'external_userid' => $userInfo['external_userid'], 'add_tag' => $add_tag, 'remove_tag' => $remove_tag]);
|
||||
if ($add_tag || $remove_tag) {
|
||||
$this->wx_qyapi->get_external_contact(['url' => 'mark_tag', 'userid' => $userInfo['userid'],
|
||||
'external_userid' => $userInfo['external_userid'], 'add_tag' => $add_tag, 'remove_tag' => $remove_tag]);
|
||||
}
|
||||
}
|
||||
$this->show_json(200, '操作成功');
|
||||
}
|
||||
@@ -308,7 +341,7 @@ class Persona extends CI_Controller
|
||||
{
|
||||
$params = $this->input->post();
|
||||
$userInfo = $params['userInfo'];
|
||||
$this->load->library('wx_qyapi', ['app' => 'lichene']);
|
||||
// $this->load->library('wx_qyapi', $this->config_qyapi);
|
||||
$remark_mobiles = $userInfo['mobile'] ? [$userInfo['mobile']] : '';
|
||||
$description = $params['of_title'] ? $params['of_title'] : '';
|
||||
if ($description && $params['of2_title']) {
|
||||
@@ -336,8 +369,10 @@ class Persona extends CI_Controller
|
||||
}
|
||||
}
|
||||
//企微标签操作
|
||||
$re_tag = $this->wx_qyapi->get_external_contact(['url' => 'mark_tag', 'userid' => $userInfo['userid'],
|
||||
'external_userid' => $userInfo['external_userid'], 'add_tag' => $add_tag, 'remove_tag' => $remove_tag]);
|
||||
if ($add_tag || $remove_tag) {
|
||||
$re_tag = $this->wx_qyapi->get_external_contact(['url' => 'mark_tag', 'userid' => $userInfo['userid'],
|
||||
'external_userid' => $userInfo['external_userid'], 'add_tag' => $add_tag, 'remove_tag' => $remove_tag]);
|
||||
}
|
||||
$c_id = $userInfo['c_id'];
|
||||
if ($c_id) {//已存在客户,更新资料
|
||||
$this->load->library('receiver/customers_entity');
|
||||
@@ -376,6 +411,32 @@ class Persona extends CI_Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:授权获取企业员工UserId
|
||||
* Created on: 2022/3/29 17:03
|
||||
* Created by: dengbw
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
*/
|
||||
private function set_auth($url = '', $params = array())
|
||||
{
|
||||
$config = $this->wx_qyapi_agent->getConfig();
|
||||
$code = $params['code'];
|
||||
if ($code) {//授权码获取微信信息
|
||||
$this->load->library('mycurl');
|
||||
$access_token = $this->wx_qyapi_agent->access_token();
|
||||
$auth_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={$access_token}&code={$code}";
|
||||
$res = $this->mycurl->httpGet($auth_url);
|
||||
return json_decode($res, true);
|
||||
} else {//静默授权获取用户openid
|
||||
$this->load->helper('url');
|
||||
$redirect_uri = urlencode($url);
|
||||
$auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['corpid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
|
||||
redirect($auth_url);
|
||||
}
|
||||
}
|
||||
|
||||
private function show_json($code, $msg, $info = [])
|
||||
{
|
||||
$data['code'] = $code;
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title><?= $_title ?></title>
|
||||
<link rel="stylesheet" href="/css/h5/persona/h5.css?v=1">
|
||||
<script src="https://qs.haodian.cn/web/javascript/jquery.3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="https://qs.haodian.cn/web/javascript/vue.2.6.10.min.js"></script>
|
||||
<script type="text/javascript" src="https://qs.haodian.cn/web/javascript/qs.js"></script>
|
||||
<script type="text/javascript" src="https://qs.haodian.cn/web/javascript/mDialog.js"></script>
|
||||
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
|
||||
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="bg-f7">
|
||||
<div id="app">
|
||||
<div class="container">
|
||||
<div class="inner30">
|
||||
<div class="inner30 bg-fff ulib-r10">
|
||||
<div class="relative">
|
||||
<img class="block imgsize-90X90 ulib-r5" :src="userInfo.avatar" alt="#"/>
|
||||
<div class="absolute pl100 box-middle font-30">
|
||||
<span class="text-middle">{{userInfo.name}}</span>
|
||||
<i class="text-middle iconfont icon-nanxing color-2b78f5" v-if="userInfo.gender==1"></i>
|
||||
<i class="text-middle iconfont icon-nvshangjia color-fb3aab" v-if="userInfo.gender==2"></i>
|
||||
<span class="text-middle color-36b229">{{userInfo.source}}</span>
|
||||
</div>
|
||||
<button :class="'absolute right-0 box-middle btn pt15 pb15 pl30 pr30 text-center font-30 color-fff ulib-r10 ' + [submitFlag?'bg-b5':'bg-3f91fd']"
|
||||
:disabled="submitFlag" @click="postToBiz()">到店
|
||||
</button>
|
||||
</div>
|
||||
<!-- <div class="bg-f7 mt30 pt20 pb20 pl30 pr30 font-30 color-2b78f5 ulib-r10">点击关联企业</div> -->
|
||||
<div class="mt20 pl140 relative bbs-1-eee last-b-none">
|
||||
<div class="absolute left-0 box-middle font-28 color-666">手机号</div>
|
||||
<div v-if="userInfo.c_id" class="pt10 pb10 text-right font-28">{{userInfo.mobile}}</div>
|
||||
<input v-else class="wp100 pl20 pr20 pt30 pb30 font-28 bds-1-ddd bds-none text-right" type="tel"
|
||||
placeholder="请输入客户手机号" v-model="userInfo.mobile"/>
|
||||
</div>
|
||||
<div class="mt20 pl140 relative bbs-1-eee last-b-none">
|
||||
<div class="absolute left-0 box-middle font-28 color-666">线索来源</div>
|
||||
<div class="pt10 pb10 text-right">
|
||||
<select :class="'bds-none font-28 bg-fff ' + [of_id == 0 ? 'color-ccc' : 'color-333']"
|
||||
v-model="of_id" @change="changeOf1" id="id-of_id">
|
||||
<option :value="0">请选择</option>
|
||||
<option :value="item.id" v-for="item in sources">{{item.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt20 pl140 relative bbs-1-eee last-b-none"
|
||||
v-if="of_id_index>-1&&sources[of_id_index].list.length>0">
|
||||
<div class="absolute left-0 box-middle font-28 color-666">{{sources[of_id_index].name}}</div>
|
||||
<div class="pt10 pb10 text-right">
|
||||
<select :class="'bds-none font-28 bg-fff ' + [of2_id == 0 ? 'color-ccc' : 'color-333']"
|
||||
v-model="of2_id" id="id-of2_id">
|
||||
<option :value="0">请选择</option>
|
||||
<option :value="item.id" v-for="item in sources[of_id_index].list">{{item.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt30 inner30 pb50 bg-fff ulib-r10">
|
||||
<div class="mt20 font-36 text-center text-bold">客户画像</div>
|
||||
<div class="relative mt40" v-for="(list,i) in taglList">
|
||||
<div class="font-28">
|
||||
<span class="text-middle">{{list.name}}</span>
|
||||
<span class="text-middle font-24" v-if="list.type=='radio'">(单选)</span>
|
||||
<span class="text-middle font-24" v-if="list.type=='checkbox'">(多选)</span>
|
||||
</div>
|
||||
<div class="fn-clear" v-if="list.type=='radio'">
|
||||
<div v-for="(option,j) in list.list"
|
||||
:class="'inline-block space-nowrap mt20 mr20 pt15 pb15 pl30 pr30 font-22 ulib-r10 ' + [option.checked ? 'bg-3f91fd color-fff' : 'bg-f6 color-666']"
|
||||
@click="radioPicker(i,j)">{{option.name}}
|
||||
</div>
|
||||
</div>
|
||||
<vdiv class="fn-clear" v-if="list.type=='checkbox'">
|
||||
<div v-for="(option,j) in list.list"
|
||||
:class="'inline-block space-nowrap mt20 mr20 pt15 pb15 pl30 pr30 font-22 ulib-r10 ' + [option.checked ? 'bg-3f91fd color-fff' : 'bg-f6 color-666']"
|
||||
@click="checkPicker(i,j)">{{option.name}}
|
||||
</div>
|
||||
</vdiv>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pt50 pb50 pl60 pr60">
|
||||
<button :class="'wp100 btn pt30 pb30 text-center font-32 color-fff ulib-r750 ' + [submitFlag?'bg-b5':'bg-3f91fd']"
|
||||
:disabled="submitFlag" @click="postUser()">确认保存
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var loading = mDialog.load({shade: false, text: "",});
|
||||
let hostUrl = ''
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
submitFlag: false,
|
||||
userInfo: {avatar: '/img/h5/avatar.png', c_id: 0},
|
||||
taglList: [],
|
||||
of_id_index: -1,
|
||||
of_id: 0,
|
||||
of2_id: 0,
|
||||
sources: [],
|
||||
aid: <?=$aid?>,
|
||||
user_id: "<?=$user_id?>",
|
||||
},
|
||||
created() {
|
||||
},
|
||||
computed: {},
|
||||
mounted() {
|
||||
},
|
||||
methods: {
|
||||
//选择一级线索来源
|
||||
changeOf1() {
|
||||
if (this.of_id > 0) {
|
||||
this.sources.forEach((item, index) => {
|
||||
if (item.id == this.of_id) {
|
||||
this.of_id_index = index;
|
||||
this.of2_id = 0;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.of_id_index = -1;
|
||||
}
|
||||
},
|
||||
//获取用户信息
|
||||
getUser(external_userid) {
|
||||
let that = this;
|
||||
$.ajax({
|
||||
url: '/h5/persona/get_user',
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
external_userid: external_userid,
|
||||
aid: that.aid,
|
||||
user_id: that.user_id,
|
||||
},
|
||||
beforeSend: function () {
|
||||
},
|
||||
success: function (re) {
|
||||
if (re.code == 200) {
|
||||
that.taglList = re.data['tagList'];
|
||||
that.sources = re.data['sources'];
|
||||
that.userInfo = re.data['userInfo'];
|
||||
that.of_id = re.data['of_id'];
|
||||
that.of2_id = re.data['of2_id'];
|
||||
that.of_id_index = re.data['of_id_index'];
|
||||
} else {
|
||||
mDialog.msg({content: re.msg});
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
loading && mDialog.close(loading); //关闭加载
|
||||
}
|
||||
});
|
||||
},
|
||||
//到店
|
||||
postToBiz() {
|
||||
let that = this;
|
||||
if (!that.userInfo.mobile) {
|
||||
mDialog.msg({content: "请输入手机号"});
|
||||
return
|
||||
}
|
||||
var of_title = that.of_id ? $("#id-of_id").find("option:selected").text() : '';
|
||||
var of2_title = that.of2_id ? $("#id-of2_id").find("option:selected").text() : '';
|
||||
$.ajax({
|
||||
url: '/h5/persona/post_to_biz',
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
userInfo: that.userInfo,
|
||||
taglList: that.taglList,
|
||||
of_id: that.of_id,
|
||||
of2_id: that.of2_id,
|
||||
of_title: of_title,
|
||||
of2_title: of2_title,
|
||||
aid: that.aid,
|
||||
},
|
||||
beforeSend: function () {
|
||||
loading = mDialog.load({shade: false, text: "",});
|
||||
that.submitFlag = true;
|
||||
},
|
||||
success: function (re) {
|
||||
mDialog.msg({content: re.msg});
|
||||
},
|
||||
complete: function () {
|
||||
loading && mDialog.close(loading); //关闭加载
|
||||
that.submitFlag = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
//保存
|
||||
postUser() {
|
||||
let that = this;
|
||||
if (!that.userInfo.userid || !that.userInfo.external_userid) {
|
||||
mDialog.msg({content: "保存失败"});
|
||||
return
|
||||
}
|
||||
var of_title = that.of_id ? $("#id-of_id").find("option:selected").text() : '';
|
||||
var of2_title = that.of2_id ? $("#id-of2_id").find("option:selected").text() : '';
|
||||
$.ajax({
|
||||
url: '/h5/persona/post_user',
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
userInfo: that.userInfo,
|
||||
taglList: that.taglList,
|
||||
of_id: that.of_id,
|
||||
of2_id: that.of2_id,
|
||||
of_title: of_title,
|
||||
of2_title: of2_title,
|
||||
aid: that.aid,
|
||||
},
|
||||
beforeSend: function () {
|
||||
loading = mDialog.load({shade: false, text: "",});
|
||||
that.submitFlag = true;
|
||||
},
|
||||
success: function (re) {
|
||||
mDialog.msg({content: re.msg});
|
||||
},
|
||||
complete: function () {
|
||||
loading && mDialog.close(loading); //关闭加载
|
||||
that.submitFlag = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
//单选
|
||||
radioPicker(i, j) {
|
||||
let taglList = this.taglList
|
||||
taglList[i].list.forEach(item => {
|
||||
item.checked = false
|
||||
})
|
||||
taglList[i].list[j].checked = true
|
||||
this.taglList = taglList
|
||||
},
|
||||
//多选
|
||||
checkPicker(i, j) {
|
||||
this.taglList[i].list[j].checked = !this.taglList[i].list[j].checked
|
||||
},
|
||||
}
|
||||
});
|
||||
wx.config({
|
||||
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
||||
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
||||
appId: "<?=$sign_package['appId']?>", // 必填,企业微信的corpID
|
||||
timestamp: "<?=$sign_package['timestamp']?>", // 必填,生成签名的时间戳
|
||||
nonceStr: "<?=$sign_package['nonceStr']?>", // 必填,生成签名的随机串
|
||||
signature: "<?=$sign_package['signature']?>",// 必填,签名,见 附录-JS-SDK使用权限签名算法
|
||||
jsApiList: ["agentConfig"] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
|
||||
});
|
||||
wx.ready(function () {
|
||||
wx.agentConfig({
|
||||
corpid: "<?=$sign_package_agent['appId']?>",
|
||||
agentid: "<?=$sign_package_agent['agentid']?>",
|
||||
timestamp: "<?=$sign_package_agent['timestamp']?>",
|
||||
nonceStr: "<?=$sign_package_agent['nonceStr']?>",
|
||||
signature: "<?=$sign_package_agent['signature']?>",
|
||||
jsApiList: ['getCurExternalContact', 'getContext', 'invoke'],
|
||||
success: function (res) {
|
||||
wx.invoke('getCurExternalContact', {}, function (res) {
|
||||
//var json = JSON.stringify(res);
|
||||
//mDialog.msg({content: "getCurExternalContact=" + json});
|
||||
if (res.err_msg == "getCurExternalContact:ok") {
|
||||
app.getUser(res.userId);//返回当前外部联系人userId
|
||||
//mDialog.msg({content: "userId=" + userId});
|
||||
} else {
|
||||
loading && mDialog.close(loading); //关闭加载
|
||||
}
|
||||
});
|
||||
},
|
||||
fail: function (res) {
|
||||
loading && mDialog.close(loading); //关闭加载
|
||||
//var json = JSON.stringify(res);
|
||||
//mDialog.msg({content: "agentConfig_fail=" + json});
|
||||
if (res.errMsg.indexOf('function not exist') > -1) {
|
||||
mDialog.msg({content: "版本过低请升级"});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
wx.error(function (res) {
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
EzDDSdGSiiJ9k96k
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user