Model_notice.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Model_notice extends Lin_Model
  3. {
  4. function __construct(){
  5. parent::__construct();
  6. $this->load->database();
  7. $this->table = 'notice';
  8. $this->load_table('notice');
  9. }
  10. public function get_type($shop,$type,$logisticstatus,$ordertatus)//查找符合消息发送条件的信息
  11. {
  12. if($type == 1)
  13. {
  14. return $this->find("shop = '$shop' and type = '$type' and ordertatus = '$ordertatus' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  15. }
  16. else if($type == 2)
  17. {
  18. return $this->find("shop = '$shop' and type = '$type' and logisticstatus = '$logisticstatus' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  19. }
  20. else if($type == 3)
  21. {
  22. return $this->find("shop = '$shop' and type = '$type' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  23. }
  24. }
  25. //所属店铺、模板类型、物流状态/订单状态
  26. /** 通过订单状态 */
  27. public function get_ordertatus($ordertatus)
  28. {
  29. return $this->find("ordertatus = '$ordertatus'");
  30. }
  31. public function get_go($list,$shop,$genre,$option)
  32. {
  33. //aptsmt获取订单:崔付款、确认地址
  34. $time = time();
  35. $data = $this->find("shop = '".$shop['id']."' and ".$genre." = '$option' and ktime < '$time' and jtime > '$time' and state = 1");//$genre三种模式:订单状态、物流跟踪、营销。启用状态下,有效期内搜索该店铺设置
  36. if($data)//如果可用模板配置
  37. {
  38. $message=2;
  39. $list['orderinfo'] = ($message==1)?substr($list['orderinfo'],1):$list['orderinfo'];
  40. if($message==1)
  41. {
  42. $expresscode = (isset($express['title']))?$express['title']:'';
  43. }
  44. else
  45. {
  46. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  47. }
  48. if(!isset($list['country']))
  49. {
  50. $list['waybill'] = '';
  51. $list['phone'] = '';
  52. $list['zipcode'] = '';
  53. $list['country'] = '';
  54. $list['province'] = '';
  55. $list['city'] = '';
  56. $list['address'] = '';
  57. $list['product'] = '';
  58. }
  59. $express['url'] = (isset($express['url']))?$express['url']:'';
  60. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  61. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  62. $list['name'] = (isset($list['name']))?$list['name']:'';
  63. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  64. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  65. $list['saddress'] = (isset($list['saddress']))?$list['saddress']:'';
  66. $list['baddress'] = (isset($list['baddress']))?$list['baddress']:'';
  67. $list['quantity'] = (isset($list['quantity']))?(($list['quantity'] > '1')?$list['quantity'].' packages of':''):'';
  68. $list['parameter'] = (isset($list['parameter']))?$list['parameter']:'';
  69. $ProductSKU = (isset($list['issku']))?$list['issku']:$list['sku'];
  70. $yjtime = (isset($express['yjtime']))?$express['yjtime']:'';
  71. $product = '';
  72. if($list['product'] != '')
  73. {
  74. $list['product'] = str_replace("'","",$list['product']);
  75. if($list['link'] != '' && $list['source'] != '1')
  76. {
  77. $pt = explode(',',$list['product']);
  78. $lk = explode(',',$list['link']);
  79. for($i=0;$i<count($pt);$i++)
  80. {
  81. $a = $pt[$i];
  82. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  83. if(isset($lk[$i]) && stripos($content,'<img') !== false)
  84. {
  85. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  86. }
  87. else
  88. {
  89. $product .= ($product != '')?' , '.$a:$a;
  90. }
  91. }
  92. }
  93. }
  94. $ProductName = '';
  95. $st = explode(';',trim($list['fpdata'],';'));
  96. foreach ($st as $v)
  97. {
  98. $v = explode('|',trim($v,'|'));
  99. $th = $this->producttitle->get_title($v[1]);
  100. if($th)
  101. {
  102. $ProductName .= $th['th'].', ';
  103. }
  104. else
  105. {
  106. $ProductName .= $v[1].', ';
  107. }
  108. }
  109. $ProductName = trim($ProductName,', ');
  110. $firstName = explode(' ',$list['name']);
  111. $t= array('$userName','$firstName','$orderid','$trackingNumber','$expressCompany','$expressWebsite','$contactPerson','$Bname','$Sname','$mobileNo','$zip','$country','$province','$city','$recipientAddress','$productInfo','$ShipAddress','$BillAddress','$Quantity','$parameter','$productTitle','$ProductName','$ProductSKU','$DeliveryTime',"[Smile]","[Shy]","[Tongue]","[Titter]","[Admire]","[Risus]","[Dance]","[Blow a Kiss]","[Comfort]","[Hug]","[Put on steam]","[Victory]","[Strong]","[Kiss]","[Anthomaniac]","[Grin]","[Seek]","[Call out]","[Cast accounts]","[Miser]","[Good idea]","[Grimace]","[Angel]","[Good bye]","[Drool]","[Enjoy]","[Erotomania]","[Dumbstruck]","[Thinking]","[Puzzle]","[Query]","[No money]","[Bored]","[Suspect]","[Hush]","[Complacent]","[Shake head]","[Cold]","[Awkward]","[Smirk]","[Amazed]","[However]","[Sweat]","[Loneliness]","[Sleepy]","[Faint]","[Distressed]","[Grievance]","[Sob]","[Cry]","[Wail]","[Obey]","[Sorry]","[Bye]","[Frown]","[So tired]","[Fall ill]","[Vomit]","[Fall on evil days]","[Surprised]","[Stunned]","[Shut up]","[Due to flat]","[Despise you]","[Rage]","[Angry]","[Mammon]","[Learn from lei feng]","[Wishing you prosperity]","[Waiter]","[Boss]","[Evil]","[Challenge]","[CS]","[Invisible man]","[Bomb]","[Scream]","[Beautiful girl]","[Handsome boy]","[Fortune cat]","[Deal]","[Handclap]","[Handshake]","[Lips]","[Rose]","[Wither]","[Heart]","[Heartbreak]","[Money]","[Shopping]","[Gift]","[Email]","[Phone]","[Cheers]","[Clock]","[Waiting]","[Late]","[Plane]","[Alipay]");//需要被替换的内容
  112. $h= array($list['name'],$firstName,$list['orderinfo'],$list['waybill'],$expresscode,$express['url'],$list['name'],$list['bname'],$list['sname'],$list['phone'],$list['zipcode'],$list['country'],$list['province'],$list['city'],$list['address'],$list['product'],$list['saddress'],$list['baddress'],$list['quantity'],$list['parameter'],$product,$ProductName,$ProductSKU,$yjtime,"/:000","/:001","/:002","/:003","/:004","/:005","/:006","/:007","/:008","/:009","/:010","/:011","/:012","/:013","/:014","/:015","/:016","/:017","/:018","/:019","/:020","/:021","/:022","/:023","/:024","/:025","/:026","/:027","/:028","/:029","/:030","/:031","/:032","/:033","/:034","/:035","/:036","/:037","/:038","/:039","/:040","/:041","/:042","/:043","/:044","/:045","/:046","/:047","/:048","/:049","/:050","/:051","/:052","/:053","/:054","/:055","/:056","/:057","/:058","/:059","/:060","/:061","/:062","/:063","/:064","/:065","/:066","/:067","/:068","/:069","/:070","/:071","/:072","/:073","/:074","/:075","/:076","/:077","/:078","/:079","/:080","/:081","/:082","/:083","/:084","/:085","/:086","/:087","/:088","/:089","/:090","/:091","/:092","/:093","/:094","/:095","/:096","/:097","/:098");//替换的内容
  113. $content = str_replace($t,$h,$data['content']);
  114. if($data['message'] == 1)//如果是发送邮件
  115. {
  116. if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$list['email']))
  117. {
  118. return '邮箱地址错误,请检查';exit;
  119. }
  120. $emailbt = ($data['emailtitle'] != '')?str_replace($t,$h,$data['emailtitle']):'The product you purchased has a new progress';
  121. $this->load->library('email');
  122. $config['protocol'] = 'smtp';
  123. $config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
  124. $config['smtp_port'] = 465;
  125. $config['smtp_user'] = 'service@email.supernovahair.com';
  126. $config['smtp_pass'] = 'LONGyihair374';
  127. $config['smtp_crypto'] = 'ssl';
  128. $config['crlf'] = "\r\n";
  129. $config['newline'] = "\r\n";
  130. $this->email->initialize($config);
  131. $this->email->set_newline("\r\n");
  132. $this->email->from('service@email.supernovahair.com',$shopname);
  133. $this->email->to($list['email']);//收件
  134. $this->email->subject($emailbt);//标题
  135. $this->email->message($content);//内容
  136. if ($this->email->send())
  137. {
  138. return 1;//成功
  139. }
  140. else
  141. {
  142. return '发送失败';
  143. }
  144. }
  145. else if($data['message'] == 2 && $list['userid'] != '')//如果是速卖通站内信,用户ID不为空
  146. {
  147. $ch = curl_init();
  148. $url = 'http://39.100.97.180/smtold.php';
  149. curl_setopt($ch,CURLOPT_URL,$url);
  150. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  151. curl_setopt($ch,CURLOPT_HEADER,0);
  152. curl_setopt($ch,CURLOPT_POST, 1);
  153. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  154. //设置post数据
  155. $post = array();
  156. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  157. $post['userid'] = $list['userid'];//速卖通买家ID
  158. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  159. $post['content'] = $content;//发送内容
  160. $post['code'] = $shop['code'];
  161. $post['order'] = $list['orderinfo'];
  162. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  163. $res = curl_exec($ch);
  164. curl_close($ch);
  165. $res = json_decode($res,true);
  166. if(isset($res['is_success']))
  167. {
  168. return 1;//成功
  169. }
  170. else
  171. {
  172. return isset($res['error_msg'])?$res['error_msg']:(isset($res['sub_msg'])?$res['sub_msg']:'发送失败');
  173. }
  174. }
  175. else
  176. {
  177. return '邮箱错误或者没有UserID';
  178. }
  179. }
  180. else
  181. {
  182. return '无可用站内信模板';
  183. }
  184. }
  185. public function get_god($list,$shop,$express,$notice)//单个订单整体模式
  186. {
  187. $list['orderinfo'] = ($notice['message']==1)?substr($list['orderinfo'],1):$list['orderinfo'];
  188. if($notice['message']==1)
  189. {
  190. $expresscode = (isset($express['title']))?$express['title']:'';
  191. }
  192. else
  193. {
  194. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  195. }
  196. if(!isset($list['country']))
  197. {
  198. $list['waybill'] = '';
  199. $list['phone'] = '';
  200. $list['zipcode'] = '';
  201. $list['country'] = '';
  202. $list['province'] = '';
  203. $list['city'] = '';
  204. $list['address'] = '';
  205. $list['product'] = '';
  206. }
  207. $express['url'] = (isset($express['url']))?$express['url']:'';
  208. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  209. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  210. $list['name'] = (isset($list['name']))?$list['name']:'';
  211. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  212. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  213. $list['saddress'] = (isset($list['saddress']))?$list['saddress']:'';
  214. $list['baddress'] = (isset($list['baddress']))?$list['baddress']:'';
  215. $list['quantity'] = (isset($list['quantity']))?(($list['quantity'] > '1')?$list['quantity'].' packages of':''):'';
  216. $list['parameter'] = (isset($list['parameter']))?$list['parameter']:'';
  217. $list['waybill'] = (isset($list['waybill']))?$list['waybill']:'';
  218. $ProductSKU = (isset($list['issku']))?$list['issku']:$list['sku'];
  219. $yjtime = (isset($express['yjtime']))?$express['yjtime']:'';
  220. $product = '';
  221. if($list['product'] != '')
  222. {
  223. $list['product'] = str_replace("'","",$list['product']);
  224. if($list['link'] != '' && $list['source'] != '1')
  225. {
  226. $pt = explode(',',$list['product']);
  227. $lk = explode(',',$list['link']);
  228. for($i=0;$i<count($pt);$i++)
  229. {
  230. $a = $pt[$i];
  231. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  232. if(isset($lk[$i]) && stripos($notice['content'],'<img') !== false)
  233. {
  234. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  235. }
  236. else
  237. {
  238. $product .= ($product != '')?' , '.$a:$a;
  239. }
  240. }
  241. }
  242. }
  243. $ProductName = '';
  244. $st = explode(';',trim($list['fpdata'],';'));
  245. foreach ($st as $v)
  246. {
  247. $v = explode('|',trim($v,'|'));
  248. if(isset($v[1]))
  249. {
  250. $th = $this->producttitle->get_title($v[1]);
  251. if($th)
  252. {
  253. $ProductName .= $th['th'].', ';
  254. }
  255. else
  256. {
  257. $ProductName .= $v[1].', ';
  258. }
  259. }
  260. }
  261. $ProductName = trim($ProductName,', ');
  262. $firstName = explode(' ',$list['name']);
  263. $t= array('$userName','$firstName','$orderid','$trackingNumber','$expressCompany','$expressWebsite','$contactPerson','$Bname','$Sname','$mobileNo','$zip','$country','$province','$city','$recipientAddress','$productInfo','$ShipAddress','$BillAddress','$Quantity','$parameter','$productTitle','$ProductName','$ProductSKU','$DeliveryTime',"[Smile]","[Shy]","[Tongue]","[Titter]","[Admire]","[Risus]","[Dance]","[Blow a Kiss]","[Comfort]","[Hug]","[Put on steam]","[Victory]","[Strong]","[Kiss]","[Anthomaniac]","[Grin]","[Seek]","[Call out]","[Cast accounts]","[Miser]","[Good idea]","[Grimace]","[Angel]","[Good bye]","[Drool]","[Enjoy]","[Erotomania]","[Dumbstruck]","[Thinking]","[Puzzle]","[Query]","[No money]","[Bored]","[Suspect]","[Hush]","[Complacent]","[Shake head]","[Cold]","[Awkward]","[Smirk]","[Amazed]","[However]","[Sweat]","[Loneliness]","[Sleepy]","[Faint]","[Distressed]","[Grievance]","[Sob]","[Cry]","[Wail]","[Obey]","[Sorry]","[Bye]","[Frown]","[So tired]","[Fall ill]","[Vomit]","[Fall on evil days]","[Surprised]","[Stunned]","[Shut up]","[Due to flat]","[Despise you]","[Rage]","[Angry]","[Mammon]","[Learn from lei feng]","[Wishing you prosperity]","[Waiter]","[Boss]","[Evil]","[Challenge]","[CS]","[Invisible man]","[Bomb]","[Scream]","[Beautiful girl]","[Handsome boy]","[Fortune cat]","[Deal]","[Handclap]","[Handshake]","[Lips]","[Rose]","[Wither]","[Heart]","[Heartbreak]","[Money]","[Shopping]","[Gift]","[Email]","[Phone]","[Cheers]","[Clock]","[Waiting]","[Late]","[Plane]","[Alipay]");//需要被替换的内容
  264. $h= array($list['name'],$firstName[0],$list['orderinfo'],$list['waybill'],$expresscode,$express['url'],$list['name'],$list['bname'],$list['sname'],$list['phone'],$list['zipcode'],$list['country'],$list['province'],$list['city'],$list['address'],$list['product'],$list['saddress'],$list['baddress'],$list['quantity'],$list['parameter'],$product,$ProductName,$ProductSKU,$yjtime,"/:000","/:001","/:002","/:003","/:004","/:005","/:006","/:007","/:008","/:009","/:010","/:011","/:012","/:013","/:014","/:015","/:016","/:017","/:018","/:019","/:020","/:021","/:022","/:023","/:024","/:025","/:026","/:027","/:028","/:029","/:030","/:031","/:032","/:033","/:034","/:035","/:036","/:037","/:038","/:039","/:040","/:041","/:042","/:043","/:044","/:045","/:046","/:047","/:048","/:049","/:050","/:051","/:052","/:053","/:054","/:055","/:056","/:057","/:058","/:059","/:060","/:061","/:062","/:063","/:064","/:065","/:066","/:067","/:068","/:069","/:070","/:071","/:072","/:073","/:074","/:075","/:076","/:077","/:078","/:079","/:080","/:081","/:082","/:083","/:084","/:085","/:086","/:087","/:088","/:089","/:090","/:091","/:092","/:093","/:094","/:095","/:096","/:097","/:098");//替换的内容
  265. $notice['content'] = str_replace($t,$h,$notice['content']);
  266. if($notice['emailtitle'] != '')
  267. {
  268. $notice['emailtitle'] = str_replace($t,$h,$notice['emailtitle']);
  269. $emailbt = $notice['emailtitle'];
  270. }
  271. else
  272. {
  273. $emailbt = $shop['brandname'].' Hair Service- Order Confirmation #'.$list['orderinfo'];
  274. }
  275. if($notice['message'] == 1)//如果是发送邮件
  276. {
  277. if(!$notice['email']['smtp_host'] || !$notice['email']['smtp_user'] || !$notice['email']['smtp_pass'])
  278. {
  279. return '此店铺没有配置邮件服务器信息!';exit;
  280. }
  281. if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$list['email']))
  282. {
  283. return '邮箱地址错误,请检查';exit;
  284. }
  285. if($notice['email']['smtp_host'] == 'smtp.gmail.com')
  286. {
  287. $ch = curl_init();
  288. $url = 'http://e.wepolicy.cn/';
  289. curl_setopt($ch,CURLOPT_URL,$url);
  290. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  291. curl_setopt($ch,CURLOPT_HEADER,0);
  292. curl_setopt($ch,CURLOPT_POST, 1);
  293. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  294. //设置post数据
  295. $post = array();
  296. $post['notice'] = $notice;
  297. $post['list'] = $list;
  298. $post['shop'] = $order;
  299. $post['emailbt'] = $emailbt;
  300. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  301. $res = curl_exec($ch);
  302. curl_close($ch);
  303. $res = json_decode($res,true);
  304. if($res)
  305. {
  306. return $res;//成功
  307. }
  308. else
  309. {
  310. return '发送失败';
  311. }
  312. }
  313. else
  314. {
  315. $this->load->library('email');
  316. $config['protocol'] = $notice['email']['protocol'];
  317. $config['smtp_host'] = $notice['email']['smtp_host'];
  318. $config['smtp_port'] = $notice['email']['smtp_port'];
  319. $config['smtp_timeout']='30';
  320. $config['smtp_user'] = $notice['email']['smtp_user'];
  321. $config['smtp_pass'] = $notice['email']['smtp_pass'];
  322. $config['smtp_crypto'] = $notice['email']['smtp_crypto'];
  323. $config['crlf'] = "\r\n";
  324. $config['newline'] = "\r\n";
  325. if(stripos($notice['content'],'</p>') !== false)
  326. {
  327. $notice['content'] = str_replace(array('<p>','<p style="'),array('<p style="margin:0px;">','<p style="margin:0px;'),$notice['content']);
  328. $config['mailtype'] = "html";
  329. }
  330. $this->email->initialize($config);
  331. $this->email->set_newline("\r\n");
  332. $this->email->from($notice['email']['smtp_user'],$shop['shopname']);//发送方
  333. $this->email->to($list['email']);//收件
  334. $this->email->subject($emailbt);//标题
  335. $this->email->message($notice['content']);//内容
  336. if ($this->email->send())
  337. {
  338. return 1;
  339. }
  340. else
  341. {
  342. return $this->email->print_debugger(array('headers'));
  343. }
  344. }
  345. }
  346. else if($notice['message'] == 2 && $list['userid'] != '')//如果是速卖通站内信,用户ID不为空
  347. {
  348. /**
  349. $ch = curl_init();
  350. $url = 'http://39.100.97.180/smtold.php';
  351. curl_setopt($ch,CURLOPT_URL,$url);
  352. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  353. curl_setopt($ch,CURLOPT_HEADER,0);
  354. curl_setopt($ch,CURLOPT_POST, 1);
  355. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  356. //设置post数据
  357. $post = array();
  358. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  359. $post['userid'] = $list['userid'];//速卖通买家ID
  360. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  361. $post['content'] = $notice['content'];//发送内容
  362. $post['code'] = $shop['code'];
  363. $post['order'] = $list['orderinfo'];
  364. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  365. $res = curl_exec($ch);
  366. curl_close($ch);
  367. $res = json_decode($res,true);
  368. if(isset($res['is_success']))
  369. {
  370. return 1;//成功
  371. }
  372. else
  373. {
  374. return $res;
  375. }
  376. **/
  377. }
  378. else if($notice['message'] == 3 && $list['user_id'] != '')//如果是TT会话,用户ID不为空
  379. {
  380. $url = 'https://open-api.tiktokglobalshop.com';
  381. $link = '/customer_service/202309/conversations';
  382. $time = time();
  383. $post['buyer_user_id'] = $list['user_id'];
  384. $queryParams['shop_cipher'] =$shop['shop_cipher'];
  385. //$queryParams['shop_id'] =$shop['codeid'];
  386. $queryParams['app_key'] =$shop['app_key'];
  387. $queryParams['timestamp'] =$time;
  388. $link .= '?'.http_build_query($queryParams);
  389. $sign = $this->apitt->sign($link,$shop['app_secret'],$post);
  390. $url .= $link.'&sign='.$sign;
  391. $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
  392. $res = $this->apitt->su_curl($post,$url,$headers);
  393. $res = json_decode($res,true);
  394. if(isset($res['data']['conversation_id']))
  395. {
  396. $f = $this->_ttfs($shop,$notice['content'],$res['data']['conversation_id']);
  397. if(isset($f['data']['message_id']))
  398. {
  399. return 1;//成功
  400. }
  401. else
  402. {
  403. return isset($f['message'])?'B:'.$f['message']:'发送失败';
  404. }
  405. }
  406. else
  407. {
  408. return isset($res['message'])?'A:'.$res['message']:'发送失败';
  409. }
  410. }
  411. else
  412. {
  413. return '无可用发送平台!';
  414. }
  415. }
  416. public function _ttfs($shop,$notice,$conversation_id)//TT发送信息
  417. {
  418. $url = 'https://open-api.tiktokglobalshop.com';
  419. $link = '/customer_service/202309/conversations/'.$conversation_id.'/messages';
  420. $time = time();
  421. $notice = str_replace('</p>','\n',$notice);
  422. $post['type'] = 'TEXT';
  423. $post['content'] = '{"content": "'.strip_tags($notice).'"}';
  424. //$queryParams['access_token'] = $shop['token'];
  425. $queryParams['shop_cipher'] = $shop['shop_cipher'];
  426. $queryParams['shop_id'] = $shop['codeid'];
  427. $queryParams['app_key'] = $shop['app_key'];
  428. $queryParams['version'] = '202309';
  429. $queryParams['timestamp'] =$time;
  430. $link .= '?'.http_build_query($queryParams);
  431. $sign = $this->apitt->sign($link,$shop['app_secret'],$post);
  432. $url .= $link.'&sign='.$sign;
  433. $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
  434. $res = $this->apitt->su_curl($post,$url,$headers);
  435. $res = json_decode($res,true);
  436. return $res;
  437. }
  438. public function get_smtone($list,$shop,$content)//单个订单非快递信息模式模式
  439. {
  440. if(!isset($list['country']))
  441. {
  442. $list['waybill'] = '';
  443. $list['phone'] = '';
  444. $list['zipcode'] = '';
  445. $list['country'] = '';
  446. $list['province'] = '';
  447. $list['city'] = '';
  448. $list['address'] = '';
  449. $list['product'] = '';
  450. }
  451. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  452. $express['url'] = (isset($express['url']))?$express['url']:'';
  453. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  454. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  455. $list['name'] = (isset($list['name']))?$list['name']:'';
  456. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  457. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  458. $product = '';
  459. if($list['product'] != '')
  460. {
  461. $list['product'] = str_replace("'","",$list['product']);
  462. if($list['link'] != '' && $list['source'] != '1')
  463. {
  464. $pt = explode(',',$list['product']);
  465. $lk = explode(',',$list['link']);
  466. for($i=0;$i<count($pt);$i++)
  467. {
  468. $a = $pt[$i];
  469. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  470. if(isset($lk[$i]) && stripos($content,'<img') !== false)
  471. {
  472. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  473. }
  474. else
  475. {
  476. $product .= ($product != '')?' , '.$a:$a;
  477. }
  478. }
  479. }
  480. }
  481. $firstName = explode(' ',$list['name']);
  482. $t= array('$userName','$firstName','$orderid','$trackingNumber','$expressCompany','$expressWebsite','$contactPerson','$Bname','$Sname','$mobileNo','$zip','$country','$province','$city','$recipientAddress','$productInfo','$ShipAddress','$BillAddress','$Quantity','$parameter','$productTitle',"[Smile]","[Shy]","[Tongue]","[Titter]","[Admire]","[Risus]","[Dance]","[Blow a Kiss]","[Comfort]","[Hug]","[Put on steam]","[Victory]","[Strong]","[Kiss]","[Anthomaniac]","[Grin]","[Seek]","[Call out]","[Cast accounts]","[Miser]","[Good idea]","[Grimace]","[Angel]","[Good bye]","[Drool]","[Enjoy]","[Erotomania]","[Dumbstruck]","[Thinking]","[Puzzle]","[Query]","[No money]","[Bored]","[Suspect]","[Hush]","[Complacent]","[Shake head]","[Cold]","[Awkward]","[Smirk]","[Amazed]","[However]","[Sweat]","[Loneliness]","[Sleepy]","[Faint]","[Distressed]","[Grievance]","[Sob]","[Cry]","[Wail]","[Obey]","[Sorry]","[Bye]","[Frown]","[So tired]","[Fall ill]","[Vomit]","[Fall on evil days]","[Surprised]","[Stunned]","[Shut up]","[Due to flat]","[Despise you]","[Rage]","[Angry]","[Mammon]","[Learn from lei feng]","[Wishing you prosperity]","[Waiter]","[Boss]","[Evil]","[Challenge]","[CS]","[Invisible man]","[Bomb]","[Scream]","[Beautiful girl]","[Handsome boy]","[Fortune cat]","[Deal]","[Handclap]","[Handshake]","[Lips]","[Rose]","[Wither]","[Heart]","[Heartbreak]","[Money]","[Shopping]","[Gift]","[Email]","[Phone]","[Cheers]","[Clock]","[Waiting]","[Late]","[Plane]","[Alipay]");//需要被替换的内容
  483. $h= array($list['name'],$firstName[0],$list['orderinfo'],$list['waybill'],$expresscode,$express['url'],$list['name'],$list['bname'],$list['sname'],$list['phone'],$list['zipcode'],$list['country'],$list['province'],$list['city'],$list['address'],$list['product'],$list['saddress'],$list['baddress'],$list['quantity'],$list['parameter'],$product,"/:000","/:001","/:002","/:003","/:004","/:005","/:006","/:007","/:008","/:009","/:010","/:011","/:012","/:013","/:014","/:015","/:016","/:017","/:018","/:019","/:020","/:021","/:022","/:023","/:024","/:025","/:026","/:027","/:028","/:029","/:030","/:031","/:032","/:033","/:034","/:035","/:036","/:037","/:038","/:039","/:040","/:041","/:042","/:043","/:044","/:045","/:046","/:047","/:048","/:049","/:050","/:051","/:052","/:053","/:054","/:055","/:056","/:057","/:058","/:059","/:060","/:061","/:062","/:063","/:064","/:065","/:066","/:067","/:068","/:069","/:070","/:071","/:072","/:073","/:074","/:075","/:076","/:077","/:078","/:079","/:080","/:081","/:082","/:083","/:084","/:085","/:086","/:087","/:088","/:089","/:090","/:091","/:092","/:093","/:094","/:095","/:096","/:097","/:098");//替换的内容
  484. $content = str_replace($t,$h,$content);
  485. if($list['userid'] != '')//用户ID不为空
  486. {
  487. $ch = curl_init();
  488. $url = 'http://39.100.97.180/smt.php';
  489. curl_setopt($ch,CURLOPT_URL,$url);
  490. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  491. curl_setopt($ch,CURLOPT_HEADER,0);
  492. curl_setopt($ch,CURLOPT_POST, 1);
  493. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  494. //设置post数据
  495. $post = array();
  496. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  497. $post['userid'] = $list['userid'];//速卖通买家ID
  498. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  499. $post['content'] = $content;//发送内容
  500. $post['code'] = $shop['code'];
  501. $post['order'] = $list['orderinfo'];
  502. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  503. $res = curl_exec($ch);
  504. curl_close($ch);
  505. $res = json_decode($res,true);
  506. if(isset($res['is_success']))
  507. {
  508. return 1;//成功
  509. }
  510. else
  511. {
  512. return isset($res['error_msg'])?$res['error_msg']:(isset($res['sub_msg'])?$res['sub_msg']:'发送失败');
  513. }
  514. }
  515. else
  516. {
  517. return 2;
  518. }
  519. }
  520. } //end class