|
@@ -25,7 +25,7 @@ use think\Db;
|
25
|
25
|
class Ai extends MemberApi
|
26
|
26
|
{
|
27
|
27
|
|
28
|
|
- protected $noNeedLogin = ['login', 'register','uploadCsv','uploadCsvFrom','exportCsv','dsTitle','dsTitlelist','dsTitle13','bdPicHandle','titleHandleApi'];
|
|
28
|
+ protected $noNeedLogin = ['login', 'register','uploadCsv','uploadCsvFrom','exportCsv','dsTitle','dsTitlelist','dsTitle13','bdPicHandle','titleHandleApi','dsTitlelist14','getTitleZl','getContentZl','getContent5188Zl'];
|
29
|
29
|
protected $noNeedRight = [];
|
30
|
30
|
|
31
|
31
|
//初始化
|
|
@@ -101,7 +101,7 @@ class Ai extends MemberApi
|
101
|
101
|
return json($data);
|
102
|
102
|
}
|
103
|
103
|
if(!empty($post['url'])){
|
104
|
|
- $this->csvHandle('./uploads/'.$post['url'],$post['rule'],$post['title']);
|
|
104
|
+ $this->csvHandle('./uploads/'.$post['url'],$post['rule'],$post['title'],$post['ar_type']);
|
105
|
105
|
$data = ['code' => 0, 'msg' => '提交成功', 'data' =>$post];
|
106
|
106
|
}else{
|
107
|
107
|
$data = ['code' => 1, 'msg' => '提交失败', 'data' => []];
|
|
@@ -114,7 +114,7 @@ class Ai extends MemberApi
|
114
|
114
|
* 逻辑控制器
|
115
|
115
|
* 规则的指令集和创意 如果为空 调用全局的即可 同样优先调用自身规则
|
116
|
116
|
*/
|
117
|
|
- public function csvHandle($url,$rule,$title){
|
|
117
|
+ public function csvHandle($url,$rule,$title,$ar_type){
|
118
|
118
|
// 读取CSV文件
|
119
|
119
|
$filename = $url;
|
120
|
120
|
if (file_exists($filename)) {
|
|
@@ -173,6 +173,7 @@ class Ai extends MemberApi
|
173
|
173
|
'is_use' => $is_use, //是否合法
|
174
|
174
|
'desc' => $desc, //非法原因 或者 合法匹配结果
|
175
|
175
|
'gzxh' => $rule,
|
|
176
|
+ 'ar_type' => $ar_type, //类型
|
176
|
177
|
'sj' => $task_no, //写入时间维度 批次
|
177
|
178
|
'is_use_id' => json_encode($rule_id,JSON_UNESCAPED_UNICODE), //写入具体规则id 可查询到对应规则是什么 判断是否合法
|
178
|
179
|
];
|
|
@@ -562,7 +563,8 @@ class Ai extends MemberApi
|
562
|
563
|
$id_list = Db::name('cms_zl')->where([
|
563
|
564
|
'catid'=>18,
|
564
|
565
|
'is_use' => 1,
|
565
|
|
- 'status' => 0
|
|
566
|
+ 'status' => 0,
|
|
567
|
+ 'ar_type' => 0
|
566
|
568
|
])->limit(10)->column('id');
|
567
|
569
|
dump($id_list);
|
568
|
570
|
Db::name('cms_zl')->where('id','in',$id_list)->update([
|
|
@@ -598,6 +600,7 @@ class Ai extends MemberApi
|
598
|
600
|
'is_use' => 1, //合法
|
599
|
601
|
'status' => 1,
|
600
|
602
|
'is_cf' => 0, //是否重复
|
|
603
|
+ 'ar_type' => 0
|
601
|
604
|
//'id'=>1199
|
602
|
605
|
])
|
603
|
606
|
->field('id,title,create_time,is_use_id')
|
|
@@ -637,10 +640,7 @@ class Ai extends MemberApi
|
637
|
640
|
//既然指定 不管管是否为空
|
638
|
641
|
$cy = $json['cy'.$json['is_sj']];
|
639
|
642
|
}else{
|
640
|
|
-
|
641
|
643
|
//随机
|
642
|
|
-
|
643
|
|
-
|
644
|
644
|
$sj_num = [];
|
645
|
645
|
for($i=1;$i<=6;$i++){
|
646
|
646
|
if(!empty($json['cy'.$i])){
|
|
@@ -708,7 +708,6 @@ class Ai extends MemberApi
|
708
|
708
|
'status' => 1
|
709
|
709
|
]);
|
710
|
710
|
}
|
711
|
|
-
|
712
|
711
|
/*
|
713
|
712
|
* 处理百度的的ai图片 变成本地的
|
714
|
713
|
* 定时任务处理
|
|
@@ -804,5 +803,286 @@ class Ai extends MemberApi
|
804
|
803
|
}
|
805
|
804
|
|
806
|
805
|
|
|
806
|
+ /*
|
|
807
|
+ * 定时同步 范文到自动发文
|
|
808
|
+ * http://console.zx2049.com/api/ai/dsTitlelist14
|
|
809
|
+ */
|
|
810
|
+ public function dsTitlelist14()
|
|
811
|
+ {
|
|
812
|
+ //得到最后时间
|
|
813
|
+ $row = Db::name('cms_ai')->where([
|
|
814
|
+ 'catid' => 14
|
|
815
|
+ ])
|
|
816
|
+ ->order('tb_time desc')
|
|
817
|
+ ->limit(1)
|
|
818
|
+ ->find();
|
|
819
|
+
|
|
820
|
+ //var_dump($row);
|
|
821
|
+
|
|
822
|
+ if(isset($row['tb_time'])){
|
|
823
|
+ $lasttime = $row['tb_time'];
|
|
824
|
+ }else{
|
|
825
|
+ $lasttime = 0;
|
|
826
|
+ }
|
|
827
|
+
|
|
828
|
+ //目前没有规则
|
|
829
|
+ $list = Db::name('cms_zl')->where([
|
|
830
|
+ 'catid'=>18,
|
|
831
|
+ //'is_use' => 1, //合法
|
|
832
|
+ //'status' => 1,
|
|
833
|
+ //'is_cf' => 0, //是否重复
|
|
834
|
+ 'ar_type' => 1
|
|
835
|
+ //'id'=>1199
|
|
836
|
+ ])
|
|
837
|
+ ->field('id,title,create_time,is_use_id')
|
|
838
|
+ ->where('create_time','>',$lasttime)
|
|
839
|
+ //->limit(10) //不能限制数量 不然时间查询 下次会漏掉某些时间相同的剩余数量 //要么使用状态字段 //要么使用自增id判断
|
|
840
|
+ ->order('create_time asc') //必须asc排序 先入库
|
|
841
|
+ ->select();
|
|
842
|
+
|
|
843
|
+ //dump($list);die;
|
|
844
|
+
|
|
845
|
+ foreach ($list as $index=>$row) {
|
|
846
|
+ $one = Db::name('cms_ai')->field('id,title')->where(['catid' => 14])->where('title','=',$row['title'])->find();
|
|
847
|
+
|
|
848
|
+ if(empty($one)){
|
|
849
|
+
|
|
850
|
+ //$json = strip_tags(htmlspecialchars_decode($row['is_use_id']));
|
|
851
|
+ //echo $json;
|
|
852
|
+ $json = $row['is_use_id'];
|
|
853
|
+ $json = json_decode($json,true);
|
|
854
|
+ //dump($json);die;
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+ if(!empty($json['zlj'])) {
|
|
858
|
+ //读取指令集
|
|
859
|
+ $zlj = $json['zlj'];
|
|
860
|
+ $zlj_arr = json_decode($zlj, true);
|
|
861
|
+ $zlj_end = end($zlj_arr);
|
|
862
|
+ $key = count($zlj_arr) - 1;
|
|
863
|
+ unset($zlj_arr[$key]);
|
|
864
|
+ $zlj = json_encode($zlj_arr, JSON_UNESCAPED_UNICODE);
|
|
865
|
+ }else{
|
|
866
|
+ $zlj_end = '0';
|
|
867
|
+ $zlj = '';
|
|
868
|
+ }
|
|
869
|
+
|
|
870
|
+ if(empty($json['is_sj'])){
|
|
871
|
+ $is_sj = "0";
|
|
872
|
+ }else{
|
|
873
|
+ $is_sj = $json['is_sj'];
|
|
874
|
+ }
|
|
875
|
+
|
|
876
|
+ //获取创意
|
|
877
|
+ if((string)$json['is_sj'] === '-1'){
|
|
878
|
+ //不需要加创意
|
|
879
|
+ $cy = '0';
|
|
880
|
+ }else{
|
|
881
|
+ if((int)$json['is_sj'] > 0){
|
|
882
|
+ //既然指定 不管管是否为空
|
|
883
|
+ $cy = $json['cy'.$json['is_sj']];
|
|
884
|
+ }else{
|
|
885
|
+ //随机
|
|
886
|
+ $sj_num = [];
|
|
887
|
+ for($i=1;$i<=6;$i++){
|
|
888
|
+ if(!empty($json['cy'.$i])){
|
|
889
|
+ $sj_num[] = $i;
|
|
890
|
+ }
|
|
891
|
+ }
|
|
892
|
+ if(!empty($sj_num)){
|
|
893
|
+ $randomKey = array_rand($sj_num);
|
|
894
|
+ $num = $sj_num[$randomKey];
|
|
895
|
+ $cy = $json['cy'.$num];
|
|
896
|
+ }else{
|
|
897
|
+ $cy = '0';
|
|
898
|
+ }
|
|
899
|
+ }
|
|
900
|
+ }
|
|
901
|
+
|
|
902
|
+ //不存在于ai中
|
|
903
|
+ $data = [
|
|
904
|
+ 'catid' => 14,
|
|
905
|
+ 'title' => $row['title'],
|
|
906
|
+ 'content' => '0',
|
|
907
|
+ 'topic_1' => '0',
|
|
908
|
+ 'topic_2' => '0',
|
|
909
|
+ 'topic_3' => '0',
|
|
910
|
+ 'didian' => '0',
|
|
911
|
+ 'dssj' => '0',
|
|
912
|
+ 'fbsj' => '0',
|
|
913
|
+ 'tb_time' => $row['create_time'],
|
|
914
|
+ 'create_time' => time(),
|
|
915
|
+ 'update_time' => time(),
|
|
916
|
+ 'status' => 0, //默认手动开启
|
|
917
|
+ 'cy' => $cy, //创意
|
|
918
|
+ 'zlj' => $zlj, //指令集 json字符串
|
|
919
|
+ 'tpzl' => $zlj_end,
|
|
920
|
+ 'sjcy' => $is_sj, //随机创意
|
|
921
|
+ 'lyjlid' => $row['id'], //来源id
|
|
922
|
+ 'sblx' => 3,//设别类型 电脑A
|
|
923
|
+ 'is_sc' => 0, //是否生成文章
|
|
924
|
+ 'pic_html' => '0',
|
|
925
|
+ 'imgs' => '{}'
|
|
926
|
+ ];
|
|
927
|
+ $run = Db::name('cms_ai')->insert($data);
|
|
928
|
+ Db::name('cms_zl')->where('id',$row['id'])->update(['is_cf'=>2]); //已检测 同步
|
|
929
|
+ echo $run;
|
|
930
|
+ }else{
|
|
931
|
+ //更新为重复记录
|
|
932
|
+ Db::name('cms_zl')->where('id',$row['id'])->update(['is_cf'=>1]);
|
|
933
|
+ echo $row['title']."已存在,更新为重复记录";
|
|
934
|
+ }
|
|
935
|
+ }
|
|
936
|
+ }
|
|
937
|
+
|
|
938
|
+ /*
|
|
939
|
+ * 自动范文 根据标题生成指令
|
|
940
|
+ * http://console.zx2049.com/api/ai/getTitleZl
|
|
941
|
+ */
|
|
942
|
+ public function getTitleZl(){
|
|
943
|
+ $title = request()->get('title');
|
|
944
|
+ $zl = [
|
|
945
|
+ '你是一位资深的职称评审专家,你非常擅长于在职场评审领域利用用户的痛点来构思和创作文章,你写的每一篇关于“职称评审”的文章都能被百度搜索引擎收录,并能获得大量的用户点击和阅读,你写的文章非常具有可阅读性和实用性,你写的文章结构非常的简洁明了,你写的文章的原创度达到100%,现在请你以这个身份来帮我写文章可以吗?如果可以,请回复可以!并等到我下一步指令',
|
|
946
|
+ '以你最擅长的“职场评审”这个领域为切入点,以这个“'.$title.'”为关键词,根据百度SEO软文的规则生成爆款文章的标题,具体要求如下:1、{'.$title.'}这个只是关键词,并非标题,但需要在标题中完整的出现或以分段的方式出现。 2、标题控制在20个文字以内。 3、标题要从用户的角度出发,以用户在”职称评审“过程中的痛点为切入。'
|
|
947
|
+ ];
|
|
948
|
+ $res = [
|
|
949
|
+ 'code' => 0,
|
|
950
|
+ 'msg' => ''.$title,
|
|
951
|
+ 'data' => $zl
|
|
952
|
+ ];
|
|
953
|
+ return json($res);
|
|
954
|
+ }
|
|
955
|
+
|
|
956
|
+ /*
|
|
957
|
+ * 获取文章指令
|
|
958
|
+ * http://console.zx2049.com/api/ai/getContentZl?id=1863
|
|
959
|
+ */
|
|
960
|
+ public function getContentZl(){
|
|
961
|
+ $id = request()->get('id');
|
|
962
|
+ //查询文章
|
|
963
|
+ $row = Db::name('cms_ai')->where('id',$id)->find();
|
|
964
|
+ //var_dump($row);
|
|
965
|
+ $title_html = strip_tags($row['title_html']);
|
|
966
|
+ $title_html = str_replace('"','',$title_html);
|
|
967
|
+
|
|
968
|
+ $zl = ['文章标题:“'.$title_html.'”。文章内容:请根据用户的述求或痛点来提供实质性的内容以达到充分解决用户的问题。文章关键词:'.$row['title'].'(强调:文章中的“'.$row['title'].'”这个词完整的出现次数不低于6次,不高于8次,且必须语句通顺,并合理安排出现的位置)。文章要求:1、文章的长度不低于1500字。2、文章的段落结构分明,具有很好的可观赏性,每个段落不超过150个字。3、文章中以第一人称的视角来进行经验阐述。4、文章尽可能简洁明了,并增加文章的感染力和节奏感;5、文章让别人一看就认为这篇文章是人工撰写的,所以请尽量使用口语化的表述方式(口语化是指:人与人之间常规沟通使用的语气、语调、用词等)。6、文章具有非常好的可阅读性,能够充分的调动用户的情绪!7、确保文章中的语句在全网的任何文章中都没有使用过!!!8、再次强调:文章中使用的语句在全网的任何文章中都没有使用过!!!'];
|
|
969
|
+ $res = [
|
|
970
|
+ 'code' => 0,
|
|
971
|
+ 'msg' => ''.$id,
|
|
972
|
+ 'data' => $zl
|
|
973
|
+ ];
|
|
974
|
+ return json($res);
|
|
975
|
+ }
|
|
976
|
+
|
|
977
|
+ /*
|
|
978
|
+ * 5118获取文章内容
|
|
979
|
+ * http://console.zx2049.com/api/ai/getContent5188Zl?id=1864
|
|
980
|
+ */
|
|
981
|
+ public function getContent5188Zl(){
|
|
982
|
+ $id = request()->get('id');
|
|
983
|
+ //查询文章
|
|
984
|
+ $row = Db::name('cms_ai')->where('id',$id)->find();
|
|
985
|
+ //var_dump($row);
|
|
986
|
+ //判断是否被转义
|
|
987
|
+ if(strpos($row['content'],'<') !== false) {
|
|
988
|
+ $content = htmlspecialchars_decode($row['content']);
|
|
989
|
+ } else {
|
|
990
|
+ $content = $row['content'];
|
|
991
|
+ }
|
|
992
|
+
|
|
993
|
+ //使用采集插件进行html代码解析
|
|
994
|
+ //发送post进行处理
|
|
995
|
+ //http://workerman.dev.zx2049.com/index/index/hello
|
|
996
|
+ $post_data = ['html'=>$content];
|
|
997
|
+ $html = $this->curl_request('http://workerman.dev.zx2049.com/index/index/handleHtmlDom',$post_data);
|
|
998
|
+ //var_dump($html);die;
|
|
999
|
+
|
|
1000
|
+ //$title_html = strip_tags($row['title_html']);
|
|
1001
|
+ //$title_html = str_replace('"','',$title_html);
|
|
1002
|
+
|
|
1003
|
+ $str = $this->html2text($html);
|
|
1004
|
+ $str = explode('-换行-',$str);
|
|
1005
|
+ //var_dump($str);die;
|
|
1006
|
+ //echo '<textarea id="div1 js-do=" inpttxt"="" class="inptTxt fontfamily" placeholder="请输入要检测的文本内容,不超过3000字">'.$str.'</textarea>';die;
|
|
1007
|
+
|
|
1008
|
+ //去除空
|
|
1009
|
+ $zl = [];
|
|
1010
|
+ foreach ($str as $k=>$r){
|
|
1011
|
+ if(!empty($r)){
|
|
1012
|
+ $zl[] = $r;
|
|
1013
|
+ }
|
|
1014
|
+ }
|
|
1015
|
+
|
|
1016
|
+ $res = [
|
|
1017
|
+ 'code' => 0,
|
|
1018
|
+ 'msg' => ''.$id,
|
|
1019
|
+ 'data' => $zl
|
|
1020
|
+ ];
|
|
1021
|
+ return json($res);
|
|
1022
|
+ }
|
|
1023
|
+
|
|
1024
|
+ public function html2text($str){
|
|
1025
|
+ $str = preg_replace("/<style .*?<\\/style>/is", "", $str);
|
|
1026
|
+ $str = preg_replace("/<script .*?<\\/script>/is", "", $str);
|
|
1027
|
+ $str = preg_replace("/<br \\s*\\/>/i", "-换行-", $str);
|
|
1028
|
+ $str = preg_replace("/<\\/?p>/i", "-换行-", $str);
|
|
1029
|
+ $str = preg_replace("/<\\/?td>/i", "", $str);
|
|
1030
|
+ $str = preg_replace("/<\\/?div>/i", "-换行-", $str);
|
|
1031
|
+ $str = preg_replace("/<\\/?blockquote>/i", "", $str);
|
|
1032
|
+ $str = preg_replace("/<\\/?li>/i", "-换行-", $str);
|
|
1033
|
+ $str = preg_replace("/ /i", " ", $str);
|
|
1034
|
+ $str = preg_replace("/ /i", " ", $str);
|
|
1035
|
+ $str = preg_replace("/&/i", "&", $str);
|
|
1036
|
+ $str = preg_replace("/&/i", "&", $str);
|
|
1037
|
+ $str = preg_replace("/</i", "<", $str);
|
|
1038
|
+ $str = preg_replace("/</i", "<", $str);
|
|
1039
|
+ $str = preg_replace("/“/i", '"', $str);
|
|
1040
|
+ $str = preg_replace("/&ldquo/i", '"', $str);
|
|
1041
|
+ $str = preg_replace("/‘/i", "'", $str);
|
|
1042
|
+ $str = preg_replace("/&lsquo/i", "'", $str);
|
|
1043
|
+ $str = preg_replace("/'/i", "'", $str);
|
|
1044
|
+ $str = preg_replace("/&rsquo/i", "'", $str);
|
|
1045
|
+ $str = preg_replace("/>/i", ">", $str);
|
|
1046
|
+ $str = preg_replace("/>/i", ">", $str);
|
|
1047
|
+ $str = preg_replace("/”/i", '"', $str);
|
|
1048
|
+ $str = preg_replace("/&rdquo/i", '"', $str);
|
|
1049
|
+ $str = strip_tags($str);
|
|
1050
|
+ $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
|
|
1051
|
+ $str = preg_replace("/&#.*?;/i", "", $str);
|
|
1052
|
+ return $str;
|
|
1053
|
+ }
|
807
|
1054
|
|
|
1055
|
+ //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
|
|
1056
|
+ public function curl_request( $url , $post = '' , $cookie = '' , $returnCookie = 0 ) {
|
|
1057
|
+ $curl = curl_init ( ) ;
|
|
1058
|
+ curl_setopt ( $curl , CURLOPT_URL , $url ) ;
|
|
1059
|
+ curl_setopt ( $curl , CURLOPT_USERAGENT , 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)' ) ;
|
|
1060
|
+ curl_setopt ( $curl , CURLOPT_FOLLOWLOCATION , 1 ) ;
|
|
1061
|
+ curl_setopt ( $curl , CURLOPT_AUTOREFERER , 1 ) ;
|
|
1062
|
+ curl_setopt ( $curl , CURLOPT_REFERER , "http://XXX" ) ;
|
|
1063
|
+ if ( $post ) {
|
|
1064
|
+ curl_setopt ( $curl , CURLOPT_POST , 1 ) ;
|
|
1065
|
+ curl_setopt ( $curl , CURLOPT_POSTFIELDS , http_build_query ( $post ) ) ;
|
|
1066
|
+ }
|
|
1067
|
+ if ( $cookie ) {
|
|
1068
|
+ curl_setopt ( $curl , CURLOPT_COOKIE , $cookie ) ;
|
|
1069
|
+ }
|
|
1070
|
+ curl_setopt ( $curl , CURLOPT_HEADER , $returnCookie ) ;
|
|
1071
|
+ curl_setopt ( $curl , CURLOPT_TIMEOUT , 10 ) ;
|
|
1072
|
+ curl_setopt ( $curl , CURLOPT_RETURNTRANSFER , 1 ) ;
|
|
1073
|
+ $data = curl_exec ( $curl ) ;
|
|
1074
|
+ if ( curl_errno ( $curl ) ) {
|
|
1075
|
+ return curl_error ( $curl ) ;
|
|
1076
|
+ }
|
|
1077
|
+ curl_close ( $curl ) ;
|
|
1078
|
+ if ( $returnCookie ) {
|
|
1079
|
+ list ( $header , $body ) = explode ( "\r\n\r\n" , $data , 2 ) ;
|
|
1080
|
+ preg_match_all ( "/Set\-Cookie:([^;]*);/" , $header , $matches ) ;
|
|
1081
|
+ $info [ 'cookie' ] = substr ( $matches [ 1 ] [ 0 ] , 1 ) ;
|
|
1082
|
+ $info [ 'content' ] = $body ;
|
|
1083
|
+ return $info ;
|
|
1084
|
+ } else {
|
|
1085
|
+ return $data ;
|
|
1086
|
+ }
|
|
1087
|
+ }
|
808
|
1088
|
}
|