func.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <?php
  2. function zhishiku($fromuserid,$keyword,$uniacid,$url,$addstr,$userinfo){
  3. //知识库处理模块
  4. //echo '<br>知识库模块<br>'.$keyword.$uniacid;
  5. $json = file_get_contents('json/'.$uniacid.'_keywords.json');//读取key列表
  6. $keys = json_decode($json,true);
  7. $json = file_get_contents('json/'.$uniacid.'_keys.json');//读取数字key列表
  8. $numkeys = json_decode($json,true);
  9. if(is_numeric($keyword)){
  10. $send=$keys[$numkeys[$keyword]];
  11. }else {
  12. $send=$keys[$keyword]; //$keys['关于我们'];
  13. }
  14. if ( $send<>'' ) { //判断是否是知识库设置字段
  15. if ($send['link']['title']!=''){
  16. $send['link']['title']=str_replace('id',$userinfo['id'],$send['link']['title']);
  17. $send['link']['title']=str_replace('[name]', trim($userinfo['nickname']),$send['link']['title']);
  18. }
  19. if ($send['miniprogrampage']['title']!=''){
  20. $send['miniprogrampage']['title']=str_replace('id',$userinfo['id'],$send['miniprogrampage']['title']);
  21. $send['miniprogrampage']['title']=str_replace('[name]', trim($userinfo['nickname']),$send['miniprogrampage']['title']);
  22. }
  23. if ($send['text']['content']!=''){
  24. $send['text']['content']=str_replace('[id]',$userinfo['id'],$send['text']['content']);
  25. $send['text']['content']=str_replace('[name]',trim($userinfo['nickname']),$send['text']['content']);
  26. $send['text']['content']=changeurl($send['text']['content']);
  27. $send['text']['content'].=$addstr;
  28. }
  29. $send['touser']=$fromuserid;
  30. $data=json_encode($send,JSON_UNESCAPED_UNICODE);
  31. $aaa = http_post_data($url, $data);
  32. $zt=json_decode($aaa, true)['errcode'];
  33. if ($zt!=0){//下发未成功
  34. $data='{ "touser":"'.$fromuserid.'", "msgtype":"text",
  35. "text": { "content":" 系统忙 错误代码: ' . $zt . ' " } }';
  36. $aaa = http_post_data($url, $data);
  37. }
  38. return true;
  39. }else{
  40. return false;//不是知识.
  41. }
  42. }
  43. function sendmsg($openid,$msgtype,$keyword,$postObj,$url){
  44. //消息处理模块.
  45. switch ($msgtype)
  46. {
  47. case 'text':
  48. $data1='{ "touser":"'.$openid.'", "msgtype":"text",
  49. "text": { "content":" '.$keyword.' " } }';
  50. break;
  51. case 'image':
  52. $MediaId = $postObj->MediaId;
  53. $data1=' { "touser":"'.$openid.'", "msgtype":"image",
  54. "image": { "media_id":"'.$MediaId.'" }}';
  55. break;
  56. case 'voice':
  57. $MediaId = $postObj->MediaId;
  58. $Recognition = $postObj->Recognition;
  59. $data1=' { "touser":"'.$openid.'", "msgtype":"voice",
  60. "voice": { "media_id":"'.$MediaId.'" }}';
  61. break;
  62. case 'miniprogrampage':
  63. $data1='';
  64. break;
  65. default:
  66. $data1='';
  67. }
  68. $aaa = http_post_data($url, $data1);
  69. //echo '发送消息:'.$data1.$aaa;
  70. // logger('@@@@@@@@'.$data1.$aaa);
  71. return $aaa;
  72. }
  73. function http_post_data($url, $data_string) {
  74. $ch = curl_init();
  75. curl_setopt($ch, CURLOPT_POST, 1);
  76. curl_setopt($ch, CURLOPT_URL, $url);
  77. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  78. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  79. 'Content-Type: application/json; charset=utf-8',
  80. 'Content-Length: ' . strlen($data_string))
  81. );
  82. ob_start();
  83. curl_exec($ch);
  84. $return_content = ob_get_contents();
  85. //echo $return_content."<br>";
  86. ob_end_clean();
  87. $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  88. // return array($return_code, $return_content);
  89. return $return_content;
  90. }
  91. function zhaokefumingling($fromuserid,$uniacid,$keyword,$url,$kefuarr,$website){
  92. $kefulist = json_decode(file_get_contents("json/".$uniacid."_kefulist.json"),true);
  93. //$kefuname=substr($keyword,7);
  94. $Kefuopenid=array_search($keyword,$kefulist,true);//找到客服id
  95. if (substr($kefuarr[$Kefuopenid],0,1)=='o')//看客服状态 客服状态over
  96. {
  97. sendmsg($fromuserid,'text','客服忙,请稍后.','',$url);//下发排队情况给用户.
  98. return false;
  99. }else{//客服接入//
  100. if($Kefuopenid==''){
  101. sendmsg($fromuserid,'text','客服休息了.请稍后再试.','',$url);//下发排队情况给用户.
  102. return false;
  103. }else{//客服在,对接开始. 如果是排队发的 则删除排队.如果是没排队发的.则不排队.
  104. $kefuarr[$Kefuopenid]=$fromuserid;
  105. //建立对接 同时通知双方. 发两次消息.
  106. exec("rm -f ".'json/'.$uniacid.'_kefu.json');
  107. $res=file_put_contents("json/".$uniacid."_kefu.json", json_encode($kefuarr));
  108. //增加获取用户信息功能. 没排队 直接进入 需要查客户信息.
  109. $json = file_get_contents("json/".$uniacid."_paidui.json");
  110. $paiduiarr = json_decode($json,true);
  111. if(array_key_exists($fromuserid,$paiduiarr)){//如果在排队则..
  112. $uid=$paiduiarr[$fromuserid]['id'];
  113. $nickname=$paiduiarr[$fromuserid]['nickname'];
  114. unset($paiduiarr[$fromuserid]);//删除它
  115. $res=file_put_contents("json/".$uniacid."_paidui.json", json_encode($paiduiarr));
  116. }else{//没排队 .就是上来就发的. 新用户就注册 老用户就获取.
  117. $users=getuser($uniacid,$fromuserid,$nickname,$website);
  118. $uid=$users['id'];
  119. $nickname=$users['nickname'];
  120. }
  121. sendmsg($Kefuopenid,'text','['.$uid.']'.$nickname.':'.$keyword.' 你好','',$url);//通知客服
  122. // $kefuname = $kefulist[$Kefuopenid];
  123. sendmsg($fromuserid,'text',$keyword.':你好,有什么可以帮到你的?','',$url);//通知客服
  124. return true;
  125. }
  126. }
  127. }
  128. function atsuoyouren($uniacid,$website,$keyword,$myopenid,$url,$toUsername){
  129. //@所有人
  130. $huncun= json_decode(alluser($uniacid,$website),true);
  131. $gjz=substr($keyword,10,strlen(trim($keyword))-10);
  132. if (substr ($keyword, -1)=='#'){
  133. $gjz=str_replace('#','|',$gjz);
  134. }
  135. $baogao=' {
  136. "title": "代发列表已经准备好!点此群发",
  137. "description": "本次准备发送: '.$huncun['count'].' 请1分钟内点击,过期失效.",
  138. "url": "'.$website.'addons/qidong_app/qunfa.php?uniacid='.$uniacid.'&keyword='.$gjz.'&tousername='.$toUsername.'&t='.time().'",
  139. "thumb_url": "'.$website.'/addons/qidong_app/icon.jpg"
  140. }';
  141. $data1='{ "touser":"'.$myopenid.'", "msgtype":"link", "link": '.$baogao.' }';
  142. $aaa = http_post_data($url, $data1); //
  143. }
  144. function zxkefu($uniacid,$kefuarr,$sqstr1){//读取在线客服列表//下次升级点击接通??
  145. $json = file_get_contents("json/".$uniacid."_kefulist.json");//客服详情页
  146. $kefulist = json_decode($json,true);
  147. $kefuopenid= array_keys($kefulist);//kfuopenid
  148. $kefuall='';
  149. $i=0;
  150. foreach ($kefuopenid as $kefuopenid){ //群发--
  151. //$kfopenid=$arr;
  152. if(substr($kefuarr[$kefuopenid],0,1)=="o"){
  153. $zt='忙碌';
  154. }else{
  155. $zt=$kefuarr[$kefuopenid];
  156. }
  157. if ($zt<>'隐身'){
  158. $i++;
  159. //$sqstr=$website."addons/qidong_app/intenet.php?zfopenid=".$fromUsername."&toUsername=".$toUsername."&appid=".$arr['Gappid']."&kfname=".$kfname;
  160. //$sqstr="\n<a href='".$sqstr."'>点此快速接通客服</a>";
  161. //$sqstr1=$website."addons/qidong_app/intenet.php?zfopenid=".$fromUsername."&toUsername=".$toUsername."&appid=".$arr['Gappid']."&kfname=".$kfname;
  162. if(($sqstr1=='') or ($zt=='忙碌')){
  163. $kefuall=$kefuall." ".$kefulist[$kefuopenid]."[".$zt."]";
  164. }else{
  165. $sqstr="\n<a href='".$sqstr1."&kfname=".$kefulist[$kefuopenid]."&kfopenid=".$kefuopenid."'>".$kefulist[$kefuopenid]."</a>";
  166. $kefuall=$kefuall." ".$sqstr."[".$zt."]";
  167. }
  168. if(($i % 2)==0){ $kefuall.="\n";}
  169. // $kefuall=$kefuall.' <a href="#">'.$kefulist[$kefuopenid].'</a>['.$zt.']';
  170. }
  171. }
  172. //logger($kefuall);
  173. return $kefuall;
  174. }
  175. function atmouren($keyword,$uniacid,$website,$fromuserid,$url,$kefuname){
  176. $stri=0;
  177. $stri= stripos($keyword,':');
  178. if ($stri==0){$stri= stripos($keyword,' ') ;}
  179. if ($stri==0){$stri= stripos($keyword,':') ;}
  180. $nid=substr($keyword,1,$stri-1); //@12:=>12
  181. $say=trim(substr($keyword,$stri+1));//发送的内容:
  182. if($say==''){$say=$kefuname.'@你 ,客服上线了,邀请你进入会话.';}
  183. //判断say最后字符是# 则是关键词消息 991#
  184. $liuuser= hiuser($uniacid,$nid,$website);
  185. $result = substr ($say, -1); //当是# 关键字图文时 .
  186. if ($result=='#'){
  187. $json = file_get_contents('json/'.$uniacid.'_keywords.json');//读取key列表
  188. $keys = json_decode($json,true);
  189. $json = file_get_contents('json/'.$uniacid.'_keys.json');//读取数字key列表
  190. $numkeys = json_decode($json,true);
  191. $gjz=substr($say,0,strlen($say)-1);
  192. if(is_numeric($gjz)){
  193. $send=$keys[$numkeys[$gjz]];
  194. } else {
  195. $send=$keys[$gjz]; //$keys['关于我们'];
  196. }
  197. $send['touser']=$liuuser['openid'];
  198. $nickname=$liuuser['nickname'];
  199. if($nickname==''){$nickname='会员'.$liuuser['id'];}
  200. $send['link']['title']=str_replace('[id]',$liuuser['id'],$send['link']['title']);
  201. $send['link']['title']=str_replace('[name]', trim($nickname),$send['link']['title']);
  202. $data=json_encode($send,JSON_UNESCAPED_UNICODE);
  203. $bbb = http_post_data($url, $data);
  204. logger('单发:'.$gjz.'-'.$data);
  205. }else{
  206. sendmsg($liuuser['openid'],'text','['.$kefuname.'@你]:'.$say,'',$url);
  207. }
  208. if (json_decode($bbb, true)['errcode']==0)
  209. { $zt='送达';
  210. //对方正在输入...哈哈
  211. $data8='{ "touser":"'.trim($liuuser['openid']).'", "command":"Typing"}';
  212. $url8='https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token='.$Atoken;
  213. $bbb = http_post_data($url8, $data8);
  214. //logger($bbb);
  215. //结束输入判断.
  216. }else{
  217. $zt='失败,可能已经离线'.json_decode($bbb, true)['errcode']; };
  218. sendmsg($fromuserid,'text','[@'.$nid.'报告]:'.$zt,'',$url);
  219. //发送消息
  220. }
  221. function glymingling($uniacid,$openid,$kehuopenid,$keyword,$jsy,$kefuarr,$url,$toUsername,$website){
  222. //处理管理员命令 @某人命令?
  223. //echo '检查命令!';$
  224. if (strpos(',清零,下一个,隐身,看留言,上班,排队,@所有人,',$keyword)>0){
  225. //此处增加管理员命令列表处理.
  226. if($keyword=='看留言'){
  227. $json = file_get_contents('json/'.$toUsername.'_lishi.json');
  228. sendmsg($openid,'text','本次获取的内容,已清空留言板:\n'.$json,'',$url);
  229. exec("rm -f ".'json/'.$toUsername.'_lishi.json');
  230. break;
  231. }
  232. if($keyword=='排队'){
  233. $json = file_get_contents("json/".$uniacid."_paidui.json");
  234. $karr = json_decode($json,true);
  235. $pdrs=count($karr);
  236. sendmsg($openid,'text','排队人数:'.$pdrs,'',$url);//发排队人数.后面再做详情.??
  237. }
  238. if($keyword=='隐身'){
  239. $kefuarr[$openid]='隐身';
  240. $res=file_put_contents("json/".$uniacid."_kefu.json", json_encode($kefuarr));
  241. sendmsg($openid,'text','设置隐身成功. 可被点名进入聊天.不能自动进入聊天.','',$url);
  242. }
  243. if($keyword=='清零'){
  244. exec("rm -f ".'json/'.$toUsername.'_paidui.json');
  245. exec("rm -f ".'json/'.$toUsername.'_token.json');
  246. exec("rm -f ".'log.xml');
  247. if (!file_exists('json/'.$toUsername.'_token.json')){
  248. $t="清零成功!";
  249. }else{
  250. $t="清零失败,请检查目录权限是否设置为777!";
  251. }
  252. sendmsg($openid,'text',$t,'',$url);
  253. }
  254. if($keyword=='上班'){
  255. $kefuarr[$openid]='空闲';
  256. $res=file_put_contents("json/".$uniacid."_kefu.json", json_encode($kefuarr));
  257. sendmsg($openid,'text','设置上班成功. 可自动接入来访客户.','',$url);
  258. }
  259. if($keyword=='下一个'){
  260. //跟现在的说再见 ?再见语?
  261. $json = file_get_contents("json/".$uniacid."_kefulist.json");//客服详情页
  262. $kefulist = json_decode($json,true);
  263. $kefuname = $kefulist[$openid];
  264. if (substr($kehuopenid,0,1)=='o'){
  265. //回复图文消息.
  266. jieshuyu($jsy,$uniacid,$kehuopenid,$website,$url);
  267. // sendmsg($kehuopenid,'text',$jsy,'',$url);//说再见.
  268. // $a=edituser($uniacid,$delid['openid'],'',$website);
  269. //$lastliao='';//最后聊天客服.
  270. edituser($uniacid,$kehuopenid,'',$website,$avartar,$zhuangtai,$kefuname);
  271. }
  272. //找到下一个客户?
  273. $json = file_get_contents("json/".$uniacid."_paidui.json");
  274. $paiduiarr = json_decode($json,true);
  275. $nextkh=array_shift($paiduiarr);//取出并从排队中删除第一个.
  276. if (substr($nextkh['openid'],0,1)=='o'){
  277. //print_r($nextkh);
  278. //echo '<hr>';
  279. //print_r('nextkhoid:'.$nextkh['openid']);
  280. sendmsg($nextkh['openid'],'text',$kefuname.':你好,久等了.','',$url);//新用户你好.
  281. $userjson=json_encode($paiduiarr);
  282. $res=file_put_contents("json/".$uniacid."_paidui.json",$userjson);//更新排队数据.
  283. $kefuarr[$openid]=$nextkh['openid'];//保存新的用户进来.;
  284. sendmsg($openid,'text','['.$nextkh['id'].']'.$nextkh['nickname'].'已经进入聊天.','',$url);//
  285. $res=file_put_contents("json/".$uniacid."_kefu.json",json_encode($kefuarr));//更新客服数据.
  286. $kefulist = json_decode(file_get_contents("json/".$uniacid."_kefulist.json"),true);
  287. $kefuname = $kefulist[$fromuserid];
  288. //sendmsg($nextkh['openid'],'text',$kefuname.':你好久等了.','',$url);//
  289. }else{//已无排队用户.修正客服表 保存.告诉客服.
  290. $kefuarr[$openid]='空闲';
  291. $res=file_put_contents("json/".$uniacid."_kefu.json",json_encode($kefuarr));//更新客服数据.
  292. sendmsg($openid,'text','已无排队用户.你的状态目前是空闲.\n常用命令: 上班 隐身 排队.','',$url);//新用户你好.
  293. }
  294. }
  295. return true;
  296. }else
  297. {
  298. return false;
  299. }
  300. }
  301. function paidui($uniacid,$openid,$website){
  302. $json = file_get_contents("json/".$uniacid."_paidui.json");
  303. $kefuarr = json_decode($json,true);
  304. if(array_key_exists($openid,$kefuarr)){
  305. return '排队中,请耐心等待.';//排队中...
  306. }else{
  307. $user=getuser($uniacid,$openid,$nickname,$website);//获取用户信息
  308. $userinfo=array('id'=>$user['id'],
  309. 'nickname'=>$user['nickname'],
  310. 'beizhu'=>$user['beizhu'],
  311. 'openid'=>$openid);
  312. $kefuarr[$openid]=$userinfo;
  313. $userjson=json_encode($kefuarr);
  314. $res=file_put_contents("json/".$uniacid."_paidui.json",$userjson);
  315. $qianmian=count($kefuarr)-1;
  316. return '已接入客服中心,前面有'.$qianmian.'人';//排队数量
  317. }
  318. }
  319. function getuser($ucid,$openid,$nickname,$website)
  320. {
  321. ///先判断缓存文件是否存在
  322. $json = file_get_contents("json/".$ucid."_user.json");
  323. $userinfos = json_decode($json,true);
  324. // $userid=$userinfos[$openid]['id'];
  325. // echo '找到缓存表:'.$userid;
  326. if (!array_key_exists($openid,$userinfos)){
  327. $token_access_url = "{$website}/app/index.php?i=".$ucid."&c=entry&a=wxapp&do=getuser&m=qidong_app&openid=".$openid."&nickname=".$nickname;
  328. // echo $token_access_url;
  329. $res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容
  330. $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP
  331. $nickname= $result['data']['wxapp'][0]['nickname'];
  332. $beizhu= $result['data']['wxapp'][0]['zhuangtai'];
  333. $lastliao= $result['data']['wxapp'][0]['lastliao'];
  334. if (trim($nickname)==null) {
  335. $nickname='会员'.$result['data']['wxapp'][0]['id'];
  336. $isid=1;
  337. }
  338. $userid=$result['data']['wxapp'][0]['id'];
  339. $data = array(
  340. 'nickname' => $nickname,
  341. 'id' => $userid,
  342. 'beizhu' => $beizhu,
  343. 'lastliao'=> $lastliao
  344. );
  345. return $data ;
  346. }else
  347. {
  348. // echo '找到缓存 直接返回;';
  349. return $userinfos[$openid];
  350. }
  351. //缓存 先去判断文件是否存在 .
  352. }
  353. //去查询 用户表 或者 客服表 找到详细信息.
  354. // 输出 : 身份[客服 或 用户 ] 状态 [ 咨询中 | 排队中 ]
  355. //规则 聊天中 不能使用1 2 3 不去查询 . 都发给管理员 .
  356. function changeurl($a){
  357. $bi= strpos($a,'[[');
  358. if ($bi==0){
  359. return $a;
  360. }else{
  361. $ei= strpos($a,']]');
  362. $qb=substr($a,0,$bi);
  363. $eb=substr($a,$ei+2);
  364. $b=substr($a,$bi+2,$ei-$bi-2);
  365. $ci=strpos($b,'|');
  366. $add=substr($b,0,$ci);
  367. $herf=substr($b,$ci+1,strlen($b)-$ci);
  368. }
  369. return $qb."<a href='".$herf."'>".$add."</a>".$eb;
  370. }
  371. function getToken($appid,$appsecret,$jsonid){
  372. $file = file_get_contents("json/{$jsonid}_token.json",true);
  373. $result = json_decode($file,true);
  374. if (time() > $result['expires']){
  375. $data = array();
  376. $data['access_token'] = getNewToken($appid,$appsecret);
  377. $data['expires']=time()+7200;
  378. $jsonStr = json_encode($data);
  379. $fp = fopen("json/{$jsonid}_token.json", "w");
  380. fwrite($fp, $jsonStr);
  381. fclose($fp);
  382. return $data['access_token'];
  383. }else{
  384. return $result['access_token'];
  385. }
  386. }
  387. function getwxinfo($token,$openid){
  388. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$token}&openid={$openid}&lang=zh_CN";
  389. // logger($url);
  390. $access_token_Arr = https_request($url);
  391. return $access_token_Arr;
  392. }
  393. function hiuser($ucid,$id,$website){
  394. $token_access_url = "{$website}/app/index.php?i=".$ucid."&c=entry&a=wxapp&do=getopenid&m=qidong_app&id=".$id;
  395. $res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容
  396. $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP
  397. $data=$result['data'][0] ;
  398. return $data ;
  399. }
  400. function alluser($ucid,$website){
  401. $token_access_url = "{$website}/app/index.php?i=".$ucid."&c=entry&a=wxapp&do=Getallopenid&m=qidong_app";
  402. $res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容
  403. $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP
  404. $data=$result['data'] ;
  405. return json_encode($data) ;
  406. }
  407. function edituser($ucid,$openid,$nickname,$website,$avartar,$zhuangtai,$lastliao) //改名取号
  408. {
  409. $token_access_url = "{$website}/app/index.php?i=".$ucid."&c=entry&a=wxapp&do=edituser&m=qidong_app&openid=".$openid."&nickname=".$nickname."&avartar=".$avartar."&lastliao=".$lastliao; //zhuangtai
  410. // echo $token_access_url;
  411. // exit;
  412. $res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容
  413. $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP
  414. $data=$result['data'];
  415. if ($data==1){$data='改名成功!';}
  416. else{$data='改名失败!';}
  417. return $data ;
  418. }
  419. function jieshuyu($bye,$uniacid,$openid,$website,$url){
  420. if(is_numeric($bye)){
  421. $json = file_get_contents('json/'.$uniacid.'_keywords.json');//读取key列表
  422. $keys = json_decode($json,true);
  423. $json = file_get_contents('json/'.$uniacid.'_keys.json');//读取数字key列表
  424. $numkeys = json_decode($json,true);
  425. $delid=getuser($uniacid,$openid,'',$website);
  426. $send=$keys[$numkeys[$bye]];
  427. if ($send['link']['title']!=''){
  428. $send['link']['title']=str_replace('id',$delid['id'],$send['link']['title']);
  429. $send['link']['title']=str_replace('[name]', trim($delid['nickname']),$send['link']['title']);
  430. }
  431. if ($send['miniprogrampage']['title']!=''){
  432. $send['miniprogrampage']['title']=str_replace('id',$delid['id'],$send['miniprogrampage']['title']);
  433. $send['miniprogrampage']['title']=str_replace('[name]', trim($delid['nickname']),$send['miniprogrampage']['title']);
  434. }
  435. if ($send['text']['content']!=''){
  436. $send['text']['content']=str_replace('[id]',$delid['id'],$send['text']['content']);
  437. $send['text']['content']=str_replace('[name]',trim($delid['nickname']),$send['text']['content']);
  438. // logger('要替换的文本:'.$send['text']['content']);
  439. $send['text']['content']=changeurl($send['text']['content']);
  440. }
  441. $send['touser']=trim($openid);
  442. $data0=json_encode($send,JSON_UNESCAPED_UNICODE);
  443. }
  444. else {
  445. $sends=$bye; //$keys['关于我们'];
  446. $jieshuyu= str_replace('[name]',$delid['nickname'],$sends);
  447. $jieshuyu=str_replace("{br}","\n",$jieshuyu);
  448. $jieshuyu=changeurl($jieshuyu);
  449. $data0='{ "touser":"'.trim($openid).'", "msgtype":"text",
  450. "text": { "content":" '.$jieshuyu.' " } }';
  451. }
  452. $aaa = http_post_data($url, $data0);
  453. logger($data0);
  454. }
  455. function Finduser($ucid,$tablename,$culname,$openid,$findname,$website){
  456. //&tablename=dc_user&culname=openid&findname=name&openid=ogMce0dAqzqm3LSCIBzoHb4XYgFU
  457. $token_access_url = "{$website}/app/index.php?i=".$ucid."&c=entry&a=wxapp&do=finduser&m=qidong_app&tablename={$tablename}&culname={$culname}&findname={$findname}&openid={$openid}";
  458. // logger( $token_access_url);
  459. $res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容
  460. logger('--------------'.$res);
  461. $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP
  462. $data=$result['data']['nickname'] ;
  463. return $data ;
  464. }
  465. ?>