common.php 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. //前后台加载的函数库
  10. //获取真实路径
  11. function get_real_path()
  12. {
  13. return APP_ROOT_PATH;
  14. }
  15. //获取GMTime
  16. function get_gmtime()
  17. {
  18. return (time() - date('Z'));
  19. }
  20. function to_date($utc_time, $format = 'Y-m-d H:i:s') {
  21. if (empty ( $utc_time )) {
  22. return '';
  23. }
  24. $timezone = intval(app_conf('TIME_ZONE'));
  25. $time = $utc_time + $timezone * 3600;
  26. return date ($format, $time );
  27. }
  28. function to_timespan($str, $format = 'Y-m-d H:i:s')
  29. {
  30. $timezone = intval(app_conf('TIME_ZONE'));
  31. //$timezone = 8;
  32. $time = intval(strtotime($str));
  33. if($time!=0)
  34. $time = $time - $timezone * 3600;
  35. return $time;
  36. }
  37. //获取客户端IP
  38. function get_client_ip() {
  39. if (getenv ( "HTTP_CLIENT_IP" ) && strcasecmp ( getenv ( "HTTP_CLIENT_IP" ), "unknown" ))
  40. $ip = getenv ( "HTTP_CLIENT_IP" );
  41. else if (getenv ( "HTTP_X_FORWARDED_FOR" ) && strcasecmp ( getenv ( "HTTP_X_FORWARDED_FOR" ), "unknown" ))
  42. $ip = getenv ( "HTTP_X_FORWARDED_FOR" );
  43. else if (getenv ( "REMOTE_ADDR" ) && strcasecmp ( getenv ( "REMOTE_ADDR" ), "unknown" ))
  44. $ip = getenv ( "REMOTE_ADDR" );
  45. else if (isset ( $_SERVER ['REMOTE_ADDR'] ) && $_SERVER ['REMOTE_ADDR'] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], "unknown" ))
  46. $ip = $_SERVER ['REMOTE_ADDR'];
  47. else
  48. $ip = "unknown";
  49. return ($ip);
  50. }
  51. //过滤注入
  52. function filter_injection(&$request)
  53. {
  54. $pattern = "/(select[\s])|(insert[\s])|(update[\s])|(delete[\s])|(from[\s])|(where[\s])/i";
  55. foreach($request as $k=>$v)
  56. {
  57. if(preg_match($pattern,$k,$match))
  58. {
  59. die("SQL Injection denied!");
  60. }
  61. if(is_array($v))
  62. {
  63. filter_injection($request[$k]);
  64. }
  65. else
  66. {
  67. if(preg_match($pattern,$v,$match))
  68. {
  69. die("SQL Injection denied!");
  70. }
  71. }
  72. }
  73. }
  74. function filter_ma_request(&$str){
  75. $search = array("../","\n","\r","\t","\r\n","'","<",">","\"","%","\\",".","/");
  76. return str_replace($search,"",$str);
  77. }
  78. //过滤请求
  79. function filter_request(&$request)
  80. {
  81. if(MAGIC_QUOTES_GPC)
  82. {
  83. foreach($request as $k=>$v)
  84. {
  85. if(is_array($v))
  86. {
  87. filter_request($v);
  88. }
  89. else
  90. {
  91. $request[$k] = stripslashes(trim($v));
  92. }
  93. }
  94. }
  95. }
  96. function adddeepslashes(&$request)
  97. {
  98. foreach($request as $k=>$v)
  99. {
  100. if(is_array($v))
  101. {
  102. adddeepslashes($v);
  103. }
  104. else
  105. {
  106. $request[$k] = addslashes(trim($v));
  107. }
  108. }
  109. }
  110. function quotes($content)
  111. {
  112. //if $content is an array
  113. if (is_array($content))
  114. {
  115. foreach ($content as $key=>$value)
  116. {
  117. //$content[$key] = mysql_real_escape_string($value);
  118. $content[$key] = addslashes($value);
  119. }
  120. } else
  121. {
  122. //if $content is not an array
  123. //$content=mysql_real_escape_string($content);
  124. $content=addslashes($content);
  125. }
  126. return $content;
  127. }
  128. //request转码
  129. function convert_req(&$req)
  130. {
  131. foreach($req as $k=>$v)
  132. {
  133. if(is_array($v))
  134. {
  135. convert_req($req[$k]);
  136. }
  137. else
  138. {
  139. if(!is_u8($v))
  140. {
  141. $req[$k] = iconv("gbk","utf-8",$v);
  142. }
  143. }
  144. }
  145. }
  146. function is_u8($string)
  147. {
  148. return preg_match('%^(?:
  149. [\x09\x0A\x0D\x20-\x7E] # ASCII
  150. | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  151. | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  152. | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  153. | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  154. | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  155. | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  156. | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  157. )*$%xs', $string);
  158. }
  159. //清除缓存
  160. function clear_cache()
  161. {
  162. //系统后台缓存
  163. clear_dir_file(get_real_path()."public/runtime/admin/Cache/");
  164. clear_dir_file(get_real_path()."public/runtime/admin/Data/_fields/");
  165. clear_dir_file(get_real_path()."public/runtime/admin/Temp/");
  166. clear_dir_file(get_real_path()."public/runtime/admin/Logs/");
  167. @unlink(get_real_path()."public/runtime/admin/~app.php");
  168. @unlink(get_real_path()."public/runtime/admin/~runtime.php");
  169. @unlink(get_real_path()."public/runtime/admin/lang.js");
  170. @unlink(get_real_path()."public/runtime/app/config_cache.php");
  171. //数据缓存
  172. clear_dir_file(get_real_path()."public/runtime/app/data_caches/");
  173. clear_dir_file(get_real_path()."public/runtime/app/db_caches/");
  174. $GLOBALS['cache']->clear();
  175. clear_dir_file(get_real_path()."public/runtime/data/");
  176. //模板页面缓存
  177. clear_dir_file(get_real_path()."public/runtime/app/tpl_caches/");
  178. clear_dir_file(get_real_path()."public/runtime/app/tpl_compiled/");
  179. @unlink(get_real_path()."public/runtime/app/lang.js");
  180. //脚本缓存
  181. clear_dir_file(get_real_path()."public/runtime/statics/");
  182. }
  183. function clear_dir_file($path)
  184. {
  185. if ( $dir = opendir( $path ) )
  186. {
  187. while ( $file = readdir( $dir ) )
  188. {
  189. $check = is_dir( $path. $file );
  190. if ( !$check )
  191. {
  192. @unlink( $path . $file );
  193. }
  194. else
  195. {
  196. if($file!='.'&&$file!='..')
  197. {
  198. clear_dir_file($path.$file."/");
  199. }
  200. }
  201. }
  202. closedir( $dir );
  203. rmdir($path);
  204. return true;
  205. }
  206. }
  207. function check_install()
  208. {
  209. if(!file_exists(get_real_path()."public/install.lock"))
  210. {
  211. clear_cache();
  212. header('Location:'.APP_ROOT.'/install');
  213. exit;
  214. }
  215. }
  216. //utf8 字符串截取
  217. function msubstr($str, $start=0, $length=15, $charset="utf-8", $suffix=true)
  218. {
  219. if(function_exists("mb_substr"))
  220. {
  221. $slice = mb_substr($str, $start, $length, $charset);
  222. if($suffix&$slice!=$str) return $slice."…";
  223. return $slice;
  224. }
  225. elseif(function_exists('iconv_substr')) {
  226. return iconv_substr($str,$start,$length,$charset);
  227. }
  228. $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
  229. $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
  230. $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
  231. $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
  232. preg_match_all($re[$charset], $str, $match);
  233. $slice = join("",array_slice($match[0], $start, $length));
  234. if($suffix&&$slice!=$str) return $slice."…";
  235. return $slice;
  236. }
  237. //字符编码转换
  238. if(!function_exists("iconv"))
  239. {
  240. function iconv($in_charset,$out_charset,$str)
  241. {
  242. require 'libs/iconv.php';
  243. $chinese = new Chinese();
  244. return $chinese->Convert($in_charset,$out_charset,$str);
  245. }
  246. }
  247. //JSON兼容
  248. if(!function_exists("json_encode"))
  249. {
  250. function json_encode($data)
  251. {
  252. require_once 'libs/json.php';
  253. $JSON = new JSON();
  254. return $JSON->encode($data);
  255. }
  256. }
  257. if(!function_exists("json_decode"))
  258. {
  259. function json_decode($data)
  260. {
  261. require_once 'libs/json.php';
  262. $JSON = new JSON();
  263. return $JSON->decode($data,1);
  264. }
  265. }
  266. //邮件格式验证的函数
  267. function check_email($email)
  268. {
  269. if(!preg_match("/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/",$email))
  270. {
  271. return false;
  272. }
  273. else
  274. return true;
  275. }
  276. /*显示隐藏中间的手机号码*/
  277. function hideMobile($mobile){
  278. if($mobile!="")
  279. return preg_replace('#(\d{3})\d{5}(\d{3})#', '${1}*****${2}',$mobile);
  280. else
  281. return "";
  282. }
  283. /*显示隐藏中间的邮箱号*/
  284. function hideEmail($email){
  285. if($email!="")
  286. {
  287. return substr($email,0,-8)."*****".substr($email,-3);
  288. }
  289. else
  290. {
  291. return "";
  292. }
  293. }
  294. //验证手机号码
  295. function check_mobile($mobile)
  296. {
  297. if(!empty($mobile) && !preg_match("/^(1[0-9]{10})?$/",$mobile))
  298. {
  299. return false;
  300. }
  301. else
  302. return true;
  303. }
  304. //验证邮编
  305. function check_postcode($postcode)
  306. {
  307. if(!empty($postcode) && !preg_match("/^([0-9]{6})(-[0-9]{5})?$/",$postcode))
  308. {
  309. return false;
  310. }
  311. else
  312. return true;
  313. }
  314. //验证验证码
  315. function check_verify_coder($verify_coder){
  316. if(!empty($verify_coder) && !preg_match("/^([0-9]{6})?$/",$verify_coder))
  317. {
  318. return false;
  319. }
  320. else
  321. return true;
  322. }
  323. function get_verify_code($verify_coder){
  324. $verify_coder_result = check_user("verify_coder",$verify_coder);
  325. //var_dump($verify_coder_result);exit;
  326. if($verify_coder_result['status']==0)
  327. {
  328. if($verify_coder_result['data']['error']==EMPTY_ERROR)
  329. {
  330. $error = "不能为空";
  331. $type = "form_tip";
  332. }
  333. if($verify_coder_result['data']['error']==EXIST_ERROR)
  334. {
  335. $error = "错误";
  336. $type="form_error";
  337. }
  338. return array("type"=>$type,"field"=>"verify_coder","info"=>"验证码".$error);
  339. }
  340. else
  341. {
  342. return array("type"=>"form_success","field"=>"verify_coder","info"=>"");
  343. }
  344. }
  345. //跳转
  346. function app_redirect($url,$time=0,$msg='')
  347. {
  348. //多行URL地址支持
  349. $url = str_replace(array("\n", "\r"), '', $url);
  350. if(empty($msg))
  351. $msg = "系统将在{$time}秒之后自动跳转到{$url}!";
  352. if (!headers_sent()) {
  353. // redirect
  354. if(0===$time) {
  355. if(substr($url,0,1)=="/")
  356. {
  357. header("Location:".get_domain().$url);
  358. }
  359. else
  360. {
  361. header("Location:".$url);
  362. }
  363. }else {
  364. header("refresh:{$time};url={$url}");
  365. echo($msg);
  366. }
  367. exit();
  368. }else {
  369. $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
  370. if($time!=0)
  371. $str .= $msg;
  372. exit($str);
  373. }
  374. }
  375. /**
  376. * 验证访问IP的有效性
  377. * @param ip地址 $ip_str
  378. * @param 访问页面 $module
  379. * @param 时间间隔 $time_span
  380. * @param 数据ID $id
  381. */
  382. function check_ipop_limit($ip_str,$module,$time_span=0,$id=0)
  383. {
  384. if(intval(app_conf('USER_SUBMIT_TIME'))>0){
  385. $time_span = intval(app_conf('USER_SUBMIT_TIME'));
  386. }
  387. $op = es_session::get($module."_".$id."_ip");
  388. if(empty($op))
  389. {
  390. $check['ip'] = get_client_ip();
  391. $check['time'] = get_gmtime();
  392. es_session::set($module."_".$id."_ip",$check);
  393. return true; //不存在session时验证通过
  394. }
  395. else
  396. {
  397. $check['ip'] = get_client_ip();
  398. $check['time'] = get_gmtime();
  399. $origin = es_session::get($module."_".$id."_ip");
  400. if($check['ip']==$origin['ip'])
  401. {
  402. if($check['time'] - $origin['time'] < $time_span)
  403. {
  404. return false;
  405. }
  406. else
  407. {
  408. es_session::set($module."_".$id."_ip",$check);
  409. return true; //不存在session时验证通过
  410. }
  411. }
  412. else
  413. {
  414. es_session::set($module."_".$id."_ip",$check);
  415. return true; //不存在session时验证通过
  416. }
  417. }
  418. }
  419. function gzip_out($content)
  420. {
  421. header("Content-type: text/html; charset=utf-8");
  422. header("Cache-control: private"); //支持页面回跳
  423. $gzip = app_conf("GZIP_ON");
  424. if( intval($gzip)==1 )
  425. {
  426. if(!headers_sent()&&extension_loaded("zlib")&&preg_match("/gzip/i",$_SERVER["HTTP_ACCEPT_ENCODING"]))
  427. {
  428. $content = gzencode($content,9);
  429. header("Content-Encoding: gzip");
  430. header("Content-Length: ".strlen($content));
  431. echo $content;
  432. }
  433. else
  434. echo $content;
  435. }else{
  436. echo $content;
  437. }
  438. }
  439. /**
  440. * 保存图片
  441. * @param array $upd_file 即上传的$_FILES数组
  442. * @param array $key $_FILES 中的键名 为空则保存 $_FILES 中的所有图片
  443. * @param string $dir 保存到的目录
  444. * @param array $whs
  445. 可生成多个缩略图
  446. 数组 参数1 为宽度,
  447. 参数2为高度,
  448. 参数3为处理方式:0(缩放,默认),1(剪裁),
  449. 参数4为是否水印 默认为 0(不生成水印)
  450. array(
  451. 'thumb1'=>array(300,300,0,0),
  452. 'thumb2'=>array(100,100,0,0),
  453. 'origin'=>array(0,0,0,0), 宽与高为0为直接上传
  454. ...
  455. ),
  456. * @param array $is_water 原图是否水印
  457. * @return array
  458. array(
  459. 'key'=>array(
  460. 'name'=>图片名称,
  461. 'url'=>原图web路径,
  462. 'path'=>原图物理路径,
  463. 有略图时
  464. 'thumb'=>array(
  465. 'thumb1'=>array('url'=>web路径,'path'=>物理路径),
  466. 'thumb2'=>array('url'=>web路径,'path'=>物理路径),
  467. ...
  468. )
  469. )
  470. ....
  471. )
  472. */
  473. //$img = save_image_upload($_FILES,'avatar','temp',array('avatar'=>array(300,300,1,1)),1);
  474. function save_image_upload($upd_file, $key='',$dir='temp', $whs=array(),$is_water=false,$need_return = false)
  475. {
  476. require_once APP_ROOT_PATH."system/utils/es_imagecls.php";
  477. $image = new es_imagecls();
  478. $image->max_size = intval(app_conf("MAX_IMAGE_SIZE"));
  479. $list = array();
  480. if(empty($key))
  481. {
  482. foreach($upd_file as $fkey=>$file)
  483. {
  484. $list[$fkey] = false;
  485. $image->init($file,$dir);
  486. if($image->save())
  487. {
  488. $list[$fkey] = array();
  489. $list[$fkey]['url'] = $image->file['target'];
  490. $list[$fkey]['path'] = $image->file['local_target'];
  491. $list[$fkey]['name'] = $image->file['prefix'];
  492. }
  493. else
  494. {
  495. if($image->error_code==-105)
  496. {
  497. if($need_return)
  498. {
  499. return array('error'=>1,'message'=>'上传的图片太大');
  500. }
  501. else
  502. echo "上传的图片太大";
  503. }
  504. elseif($image->error_code==-104||$image->error_code==-103||$image->error_code==-102||$image->error_code==-101)
  505. {
  506. if($need_return)
  507. {
  508. return array('error'=>1,'message'=>'非法图像'.$image->error_code);
  509. }
  510. else
  511. echo "非法图像";
  512. }
  513. exit;
  514. }
  515. }
  516. }
  517. else
  518. {
  519. $list[$key] = false;
  520. $image->init($upd_file[$key],$dir);
  521. if($image->save())
  522. {
  523. $list[$key] = array();
  524. $list[$key]['url'] = $image->file['target'];
  525. $list[$key]['path'] = $image->file['local_target'];
  526. $list[$key]['name'] = $image->file['prefix'];
  527. }
  528. else
  529. {
  530. if($image->error_code==-105)
  531. {
  532. if($need_return)
  533. {
  534. return array('error'=>1,'message'=>'上传的图片太大');
  535. }
  536. else
  537. echo "上传的图片太大";
  538. }
  539. elseif($image->error_code==-104||$image->error_code==-103||$image->error_code==-102||$image->error_code==-101)
  540. {
  541. if($need_return)
  542. {
  543. return array('error'=>1,'message'=>'非法图像'.$image->error_code);
  544. }
  545. else
  546. echo "非法图像";
  547. }
  548. exit;
  549. }
  550. }
  551. $water_image = APP_ROOT_PATH.app_conf("WATER_MARK");
  552. $alpha = app_conf("WATER_ALPHA");
  553. $place = app_conf("WATER_POSITION");
  554. foreach($list as $lkey=>$item)
  555. {
  556. //循环生成规格图
  557. foreach($whs as $tkey=>$wh)
  558. {
  559. $list[$lkey]['thumb'][$tkey]['url'] = false;
  560. $list[$lkey]['thumb'][$tkey]['path'] = false;
  561. if($wh[0] > 0 || $wh[1] > 0) //有宽高度
  562. {
  563. $thumb_type = isset($wh[2]) ? intval($wh[2]) : 0; //剪裁还是缩放, 0缩放 1剪裁
  564. if($thumb = $image->thumb($item['path'],$wh[0],$wh[1],$thumb_type))
  565. {
  566. $list[$lkey]['thumb'][$tkey]['url'] = $thumb['url'];
  567. $list[$lkey]['thumb'][$tkey]['path'] = $thumb['path'];
  568. if(isset($wh[3]) && intval($wh[3]) > 0)//需要水印
  569. {
  570. $paths = pathinfo($list[$lkey]['thumb'][$tkey]['path']);
  571. $path = $paths['dirname'];
  572. $path = $path."/origin/";
  573. if (!is_dir($path)) {
  574. @mkdir($path);
  575. @chmod($path, 0777);
  576. }
  577. $filename = $paths['basename'];
  578. @file_put_contents($path.$filename,@file_get_contents($list[$lkey]['thumb'][$tkey]['path']));
  579. $image->water($list[$lkey]['thumb'][$tkey]['path'],$water_image,$alpha, $place);
  580. }
  581. }
  582. }
  583. }
  584. if($is_water)
  585. {
  586. $paths = pathinfo($item['path']);
  587. $path = $paths['dirname'];
  588. $path = $path."/origin/";
  589. if (!is_dir($path)) {
  590. @mkdir($path);
  591. @chmod($path, 0777);
  592. }
  593. $filename = $paths['basename'];
  594. @file_put_contents($path.$filename,@file_get_contents($item['path']));
  595. $image->water($item['path'],$water_image,$alpha, $place);
  596. }
  597. }
  598. return $list;
  599. }
  600. function empty_tag($string)
  601. {
  602. $string = preg_replace(array("/\[img\]\d+\[\/img\]/","/\[[^\]]+\]/"),array("",""),$string);
  603. if(trim($string)=='')
  604. return $GLOBALS['lang']['ONLY_IMG'];
  605. else
  606. return $string;
  607. //$string = str_replace(array("[img]","[/img]"),array("",""),$string);
  608. }
  609. /**
  610. * utf8字符转Unicode字符
  611. * @param string $char 要转换的单字符
  612. * @return void
  613. */
  614. function utf8_to_unicode($char)
  615. {
  616. switch(strlen($char))
  617. {
  618. case 1:
  619. return ord($char);
  620. case 2:
  621. $n = (ord($char[0]) & 0x3f) << 6;
  622. $n += ord($char[1]) & 0x3f;
  623. return $n;
  624. case 3:
  625. $n = (ord($char[0]) & 0x1f) << 12;
  626. $n += (ord($char[1]) & 0x3f) << 6;
  627. $n += ord($char[2]) & 0x3f;
  628. return $n;
  629. case 4:
  630. $n = (ord($char[0]) & 0x0f) << 18;
  631. $n += (ord($char[1]) & 0x3f) << 12;
  632. $n += (ord($char[2]) & 0x3f) << 6;
  633. $n += ord($char[3]) & 0x3f;
  634. return $n;
  635. }
  636. }
  637. /**
  638. * utf8字符串分隔为unicode字符串
  639. * @param string $str 要转换的字符串
  640. * @param string $depart 分隔,默认为空格为单字
  641. * @return string
  642. */
  643. function str_to_unicode_word($str,$depart=' ')
  644. {
  645. $arr = array();
  646. $str_len = mb_strlen($str,'utf-8');
  647. for($i = 0;$i < $str_len;$i++)
  648. {
  649. $s = mb_substr($str,$i,1,'utf-8');
  650. if($s != ' ' && $s != ' ')
  651. {
  652. $arr[] = 'ux'.utf8_to_unicode($s);
  653. }
  654. }
  655. return implode($depart,$arr);
  656. }
  657. /**
  658. * utf8字符串分隔为unicode字符串
  659. * @param string $str 要转换的字符串
  660. * @return string
  661. */
  662. function str_to_unicode_string($str)
  663. {
  664. $string = str_to_unicode_word($str,'');
  665. return $string;
  666. }
  667. //分词
  668. function div_str($str)
  669. {
  670. require_once APP_ROOT_PATH."system/libs/words.php";
  671. $words = words::segment($str);
  672. $words[] = $str;
  673. return $words;
  674. }
  675. /**
  676. *
  677. * @param $tag //要插入的关键词
  678. * @param $table //表名
  679. * @param $id //数据ID
  680. * @param $field // tag_match/name_match/cate_match/locate_match
  681. */
  682. function insert_match_item($tag,$table,$id,$field)
  683. {
  684. if($tag=='')
  685. return;
  686. $unicode_tag = str_to_unicode_string($tag);
  687. $sql = "select count(*) from ".DB_PREFIX.$table." where match(".$field.") against ('".$unicode_tag."' IN BOOLEAN MODE) and id = ".$id;
  688. $rs = $GLOBALS['db']->getOne($sql);
  689. if(intval($rs) == 0)
  690. {
  691. $match_row = $GLOBALS['db']->getRow("select * from ".DB_PREFIX.$table." where id = ".$id);
  692. if($match_row[$field]=="")
  693. {
  694. $match_row[$field] = $unicode_tag;
  695. $match_row[$field."_row"] = $tag;
  696. }
  697. else
  698. {
  699. $match_row[$field] = $match_row[$field].",".$unicode_tag;
  700. $match_row[$field."_row"] = $match_row[$field."_row"].",".$tag;
  701. }
  702. $GLOBALS['db']->autoExecute(DB_PREFIX.$table, $match_row, $mode = 'UPDATE', "id=".$id, $querymode = 'SILENT');
  703. }
  704. }
  705. //封装url
  706. function url($route="index",$param=array())
  707. {
  708. $key = md5("URL_KEY_".$route.serialize($param));
  709. if(isset($GLOBALS[$key]))
  710. {
  711. $url = $GLOBALS[$key];
  712. return $url;
  713. }
  714. $url = load_dynamic_cache($key);
  715. if($url!==false)
  716. {
  717. $GLOBALS[$key] = $url;
  718. return $url;
  719. }
  720. $route_array = explode("#",$route);
  721. if(isset($param)&&$param!=''&&!is_array($param))
  722. {
  723. $param['id'] = $param;
  724. }
  725. $module = strtolower(trim($route_array[0]));
  726. $action = strtolower(trim($route_array[1]));
  727. if(!$module||$module=='index')$module="";
  728. if(!$action||$action=='index')$action="";
  729. if(true )
  730. {
  731. //原始模式
  732. $url = APP_ROOT."/index.php";
  733. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  734. {
  735. $url.="?";
  736. }
  737. if($module&&$module!='')
  738. $url .= CTL."=".$module."&";
  739. if($action&&$action!='')
  740. $url .= ACT."=".$action."&";
  741. if(count($param)>0)
  742. {
  743. foreach($param as $k=>$v)
  744. {
  745. if($k&&$v)
  746. $url =$url.$k."=".urlencode($v)."&";
  747. }
  748. }
  749. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  750. $GLOBALS[$key] = $url;
  751. set_dynamic_cache($key,$url);
  752. return $url;
  753. }
  754. else
  755. {
  756. //重写的默认
  757. $url = APP_ROOT;
  758. if($module==''&&$action==''){
  759. $url .='/index';
  760. }else{
  761. if($module&&$module!='')
  762. $url .= "/".$module;
  763. if($action&&$action!='')
  764. $url .= "-".$action;
  765. }
  766. if(count($param)>0)
  767. {
  768. $url.="/";
  769. foreach($param as $k=>$v)
  770. {
  771. $url =$url.$k."-".urlencode($v)."-";
  772. }
  773. }
  774. $route = $module."#".$action;
  775. switch ($route)
  776. {
  777. case "xxx":
  778. break;
  779. default:
  780. break;
  781. }
  782. // if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-'){
  783. // $url.='index';
  784. // }
  785. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  786. $url=trim($url);
  787. if($url==''){
  788. $url="/index.html";
  789. }else{
  790. if($module=='article_cate'){
  791. if($param['id']){
  792. if($GLOBALS['article_cates'][$param['id']]['seo_title']){
  793. if($param['p']){
  794. $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title']."?p=".$param['p'];
  795. }else{
  796. $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title'];
  797. }
  798. }else{
  799. $url.='.html';
  800. }
  801. }elseif($param['p']){
  802. $url=APP_ROOT."/article_cate?p=".$param['p'];
  803. }elseif($param['tag']){
  804. $url=APP_ROOT."/article_cate?tag=".$param['tag'];
  805. }
  806. else{
  807. $url=APP_ROOT."/article_cate";
  808. }
  809. }elseif($module=='article'){
  810. if($param['id']){
  811. if($GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']){
  812. $url=APP_ROOT."/".$GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']."/".$param['id'].".html";
  813. }else{
  814. $url.='.html';
  815. }
  816. }else{
  817. $url=APP_ROOT."/article_cate";
  818. }
  819. }else{
  820. $url.='.html';
  821. }
  822. }
  823. if($url=='')$url="/";
  824. $GLOBALS[$key] = $url;
  825. set_dynamic_cache($key,$url);
  826. return $url;
  827. }
  828. }
  829. function url_wap($route="index",$param=array())
  830. {
  831. if($GLOBALS['is_app']){
  832. $param['from_type'] = $GLOBALS['is_app'];
  833. }
  834. $key = md5("URL_WAP_KEY_".$route.serialize($param));
  835. if(isset($GLOBALS[$key]))
  836. {
  837. $url = $GLOBALS[$key];
  838. return $url;
  839. }
  840. $url = load_dynamic_cache($key);
  841. if($url!==false)
  842. {
  843. $GLOBALS[$key] = $url;
  844. return $url;
  845. }
  846. $route_array = explode("#",$route);
  847. if(isset($param)&&$param!=''&&!is_array($param))
  848. {
  849. $param['id'] = $param;
  850. }
  851. $module = strtolower(trim($route_array[0]));
  852. $action = strtolower(trim($route_array[1]));
  853. if(!$module||$module=='index')$module="";
  854. if(!$action||$action=='index')$action="";
  855. if(true)
  856. {
  857. //原始模式
  858. $url = APP_ROOT."/wap/index.php";
  859. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  860. {
  861. $url.="?";
  862. }
  863. if($module&&$module!='')
  864. $url .= "ctl=".$module."&";
  865. if($action&&$action!='')
  866. $url .= "act=".$action."&";
  867. if(count($param)>0)
  868. {
  869. foreach($param as $k=>$v)
  870. {
  871. if($k&&$v)
  872. $url =$url.$k."=".urlencode($v)."&";
  873. }
  874. }
  875. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  876. $GLOBALS[$key] = $url;
  877. set_dynamic_cache($key,$url);
  878. return $url;
  879. }
  880. else
  881. {
  882. //重写的默认
  883. $url = APP_ROOT."/wap";
  884. if($module&&$module!='')
  885. $url .= "/".$module;
  886. if($action&&$action!='')
  887. $url .= "-".$action;
  888. if(count($param)>0)
  889. {
  890. $url.="/";
  891. foreach($param as $k=>$v)
  892. {
  893. $url =$url.$k."-".urlencode($v)."-";
  894. }
  895. }
  896. $route = $module."#".$action;
  897. switch ($route)
  898. {
  899. case "xxx":
  900. break;
  901. default:
  902. break;
  903. }
  904. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  905. if($url=='')$url="/";
  906. $GLOBALS[$key] = $url;
  907. set_dynamic_cache($key,$url);
  908. return $url;
  909. }
  910. }
  911. //封装url
  912. function url_mapi($route="index",$param=array())
  913. {
  914. $key = md5("URL_APP_KEY_".$route.serialize($param));
  915. if(isset($GLOBALS[$key]))
  916. {
  917. $url = $GLOBALS[$key];
  918. return $url;
  919. }
  920. $url = load_dynamic_cache($key);
  921. if($url!==false)
  922. {
  923. $GLOBALS[$key] = $url;
  924. return $url;
  925. }
  926. $route_array = explode("#",$route);
  927. if(isset($param)&&$param!=''&&!is_array($param))
  928. {
  929. $param['id'] = $param;
  930. }
  931. $module = strtolower(trim($route_array[0]));
  932. $action = strtolower(trim($route_array[1]));
  933. if(!$module||$module=='index')$module="";
  934. if(!$action||$action=='index')$action="";
  935. if(app_conf("URL_MODEL")==0)
  936. {
  937. //原始模式
  938. $url = APP_ROOT."/index.php";
  939. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  940. {
  941. $url.="?";
  942. }
  943. if($module&&$module!='')
  944. $url .= "ctl=".$module."&";
  945. if($action&&$action!='')
  946. $url .= "act=".$action."&";
  947. if(count($param)>0)
  948. {
  949. foreach($param as $k=>$v)
  950. {
  951. if($k&&$v)
  952. $url =$url.$k."=".urlencode($v)."&";
  953. }
  954. }
  955. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  956. $GLOBALS[$key] = $url;
  957. set_dynamic_cache($key,$url);
  958. return $url;
  959. }
  960. else
  961. {
  962. //重写的默认
  963. $url = APP_ROOT;
  964. if($module&&$module!='')
  965. $url .= "/".$module;
  966. if($action&&$action!='')
  967. $url .= "-".$action;
  968. if(count($param)>0)
  969. {
  970. $url.="/";
  971. foreach($param as $k=>$v)
  972. {
  973. $url =$url.$k."-".urlencode($v)."-";
  974. }
  975. }
  976. $route = $module."#".$action;
  977. switch ($route)
  978. {
  979. case "xxx":
  980. break;
  981. default:
  982. break;
  983. }
  984. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  985. if($url=='')$url="/";
  986. $GLOBALS[$key] = $url;
  987. set_dynamic_cache($key,$url);
  988. return $url;
  989. }
  990. }
  991. //封装app_url
  992. function url_app($route="index",$param=array())
  993. {
  994. $route_array = explode("#",$route);
  995. if(isset($param)&&$param!=''&&!is_array($param))
  996. {
  997. $param['id'] = $param;
  998. }
  999. if(isset($route_array[0])){
  1000. $module = strtolower(trim($route_array[0]));
  1001. }else{
  1002. $module = "";
  1003. }
  1004. if(isset($route_array[1])){
  1005. $action = strtolower(trim($route_array[1]));
  1006. }else{
  1007. $action = "";
  1008. }
  1009. if(!$module||$module=='index')$module="";
  1010. if(!$action||$action=='index')$action="";
  1011. if(true )
  1012. {
  1013. //原始模式
  1014. $url = APP_ROOT."/index.php";
  1015. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  1016. {
  1017. $url.="?";
  1018. }
  1019. if($module&&$module!='')
  1020. $url .= CTL."=".$module."&";
  1021. if($action&&$action!='')
  1022. $url .= ACT."=".$action."&";
  1023. if(count($param)>0)
  1024. {
  1025. foreach($param as $k=>$v)
  1026. {
  1027. if($k&&$v)
  1028. $url =$url.$k."=".urlencode($v)."&";
  1029. }
  1030. }
  1031. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  1032. return $url;
  1033. }
  1034. else
  1035. {
  1036. //重写的默认
  1037. $url = APP_ROOT;
  1038. if($module==''&&$action==''){
  1039. $url .='/index';
  1040. }else{
  1041. if($module&&$module!='')
  1042. $url .= "/".$module;
  1043. if($action&&$action!='')
  1044. $url .= "-".$action;
  1045. }
  1046. if(count($param)>0)
  1047. {
  1048. $url.="/";
  1049. foreach($param as $k=>$v)
  1050. {
  1051. $url =$url.$k."-".urlencode($v)."-";
  1052. }
  1053. }
  1054. $route = $module."#".$action;
  1055. switch ($route)
  1056. {
  1057. case "xxx":
  1058. break;
  1059. default:
  1060. break;
  1061. }
  1062. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  1063. $url=trim($url);
  1064. if($url==''){
  1065. $url="/index.html";
  1066. }else{
  1067. if($module=='article_cate'){
  1068. if($param['id']){
  1069. if($GLOBALS['article_cates'][$param['id']]['seo_title']){
  1070. if($param['p']){
  1071. $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title']."?p=".$param['p'];
  1072. }else{
  1073. $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title'];
  1074. }
  1075. }else{
  1076. $url.='.html';
  1077. }
  1078. }elseif($param['p']){
  1079. $url=APP_ROOT."/article_cate?p=".$param['p'];
  1080. }elseif($param['tag']){
  1081. $url=APP_ROOT."/article_cate?tag=".$param['tag'];
  1082. }
  1083. else{
  1084. $url=APP_ROOT."/article_cate";
  1085. }
  1086. }elseif($module=='article'){
  1087. if($param['id']){
  1088. if($GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']){
  1089. $url=APP_ROOT."/".$GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']."/".$param['id'].".html";
  1090. }else{
  1091. $url.='.html';
  1092. }
  1093. }else{
  1094. $url=APP_ROOT."/article_cate";
  1095. }
  1096. }else{
  1097. $url.='.html';
  1098. }
  1099. }
  1100. if($url=='')$url="/";
  1101. return $url;
  1102. }
  1103. }
  1104. //PC端 封装url
  1105. function url_pc($route="index",$act="action",$param=array())
  1106. {
  1107. $route_array = explode("#",$route);
  1108. $act_array = explode("#",$act);
  1109. if(isset($param)&&$param!=''&&!is_array($param))
  1110. {
  1111. $param['id'] = $param;
  1112. }
  1113. if(isset($route_array[0])){
  1114. $module = strtolower(trim($route_array[0]));
  1115. }else{
  1116. $module = "";
  1117. }
  1118. if(isset($act_array[0])){
  1119. $action = strtolower(trim($act_array[0]));
  1120. }else{
  1121. $action = "";
  1122. }
  1123. if(!$module||$module=='index')$module="";
  1124. if(!$action||$action=='action')$action="";
  1125. if(true )
  1126. {
  1127. //原始模式
  1128. $url = APP_ROOT."/app/index.php";
  1129. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  1130. {
  1131. $url.="?";
  1132. }
  1133. if($module&&$module!='')
  1134. $url .= 'ctl'."=".$module."&";
  1135. if($action&&$action!='')
  1136. $url .= 'act'."=".$action."&";
  1137. if(count($param)>0)
  1138. {
  1139. foreach($param as $k=>$v)
  1140. {
  1141. if($k&&$v)
  1142. $url =$url.$k."=".urlencode($v)."&";
  1143. }
  1144. }
  1145. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  1146. return $url;
  1147. }
  1148. else
  1149. {
  1150. //重写的默认
  1151. $url = APP_ROOT;
  1152. if($module==''&&$action==''){
  1153. $url .='/index';
  1154. }else{
  1155. if($module&&$module!='')
  1156. $url .= "/".$module;
  1157. if($action&&$action!='')
  1158. $url .= "/".$action;
  1159. }
  1160. if(count($param)>0)
  1161. {
  1162. $url.="/";
  1163. foreach($param as $k=>$v)
  1164. {
  1165. $url =$url.$k."-".urlencode($v)."-";
  1166. }
  1167. }
  1168. $route = $module."#".$action;
  1169. $cat = $module."#".$action;
  1170. switch ($route)
  1171. {
  1172. case "xxx":
  1173. break;
  1174. default:
  1175. break;
  1176. }
  1177. switch ($cat)
  1178. {
  1179. case "xxx":
  1180. break;
  1181. default:
  1182. break;
  1183. }
  1184. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  1185. $url=trim($url);
  1186. if($url==''){
  1187. $url="/index.html";
  1188. }else{
  1189. if($module=='article_cate'){
  1190. if($param['id']){
  1191. if($GLOBALS['article_cates'][$param['id']]['seo_title']){
  1192. if($param['p']){
  1193. $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title']."?p=".$param['p'];
  1194. }else{
  1195. $url=APP_ROOT."/".$GLOBALS['article_cates'][$param['id']]['seo_title'];
  1196. }
  1197. }else{
  1198. $url.='.html';
  1199. }
  1200. }elseif($param['p']){
  1201. $url=APP_ROOT."/article_cate?p=".$param['p'];
  1202. }elseif($param['tag']){
  1203. $url=APP_ROOT."/article_cate?tag=".$param['tag'];
  1204. }
  1205. else{
  1206. $url=APP_ROOT."/article_cate";
  1207. }
  1208. }elseif($module=='article'){
  1209. if($param['id']){
  1210. if($GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']){
  1211. $url=APP_ROOT."/".$GLOBALS['article_cates'][$GLOBALS['articles'][$param['id']]['cate_id']]['seo_title']."/".$param['id'].".html";
  1212. }else{
  1213. $url.='.html';
  1214. }
  1215. }else{
  1216. $url=APP_ROOT."/article_cate";
  1217. }
  1218. }else{
  1219. $url.='.html';
  1220. }
  1221. }
  1222. if($url=='')$url="/";
  1223. return $url;
  1224. }
  1225. }
  1226. //微信端 封装url
  1227. function url_wx($route="index",$act="action",$param=array())
  1228. {
  1229. if($GLOBALS['is_app']){
  1230. $param['from_type'] = $GLOBALS['is_app'];
  1231. }
  1232. $key = md5("URL_WAP_KEY_".$route.serialize($param));
  1233. if(isset($GLOBALS[$key]))
  1234. {
  1235. $url = $GLOBALS[$key];
  1236. return $url;
  1237. }
  1238. $url = load_dynamic_cache($key);
  1239. if($url!==false)
  1240. {
  1241. $GLOBALS[$key] = $url;
  1242. return $url;
  1243. }
  1244. $route_array = explode("#",$route);
  1245. if(isset($param)&&$param!=''&&!is_array($param))
  1246. {
  1247. $param['id'] = $param;
  1248. }
  1249. $module = strtolower(trim($route_array[0]));
  1250. $action = strtolower(trim($route_array[1]));
  1251. if(!$module||$module=='index')$module="";
  1252. if(!$action||$action=='index')$action="";
  1253. if(true)
  1254. {
  1255. //原始模式
  1256. $url = APP_ROOT."/index.php";
  1257. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  1258. {
  1259. $url.="?";
  1260. }
  1261. if($module&&$module!='')
  1262. $url .= "ctl=".$module."&";
  1263. if($action&&$action!='')
  1264. $url .= "act=".$action."&";
  1265. if(count($param)>0)
  1266. {
  1267. foreach($param as $k=>$v)
  1268. {
  1269. if($k&&$v)
  1270. $url =$url.$k."=".urlencode($v)."&";
  1271. }
  1272. }
  1273. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  1274. $GLOBALS[$key] = $url;
  1275. set_dynamic_cache($key,$url);
  1276. return $url;
  1277. }
  1278. else
  1279. {
  1280. //重写的默认
  1281. $url = APP_ROOT;
  1282. if($module&&$module!='')
  1283. $url .= "/".$module;
  1284. if($action&&$action!='')
  1285. $url .= "-".$action;
  1286. if(count($param)>0)
  1287. {
  1288. $url.="/";
  1289. foreach($param as $k=>$v)
  1290. {
  1291. $url =$url.$k."-".urlencode($v)."-";
  1292. }
  1293. }
  1294. $route = $module."#".$action;
  1295. switch ($route)
  1296. {
  1297. case "xxx":
  1298. break;
  1299. default:
  1300. break;
  1301. }
  1302. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  1303. if($url=='')$url="/";
  1304. $GLOBALS[$key] = $url;
  1305. set_dynamic_cache($key,$url);
  1306. return $url;
  1307. }
  1308. }
  1309. //手机端 访问根目录的url
  1310. function url_root($route="index",$param=array())
  1311. {
  1312. $key = md5("URL_KEY_".$route.serialize($param));
  1313. if(isset($GLOBALS[$key]))
  1314. {
  1315. $url = $GLOBALS[$key];
  1316. return $url;
  1317. }
  1318. $url = load_dynamic_cache($key);
  1319. if($url!==false)
  1320. {
  1321. $GLOBALS[$key] = $url;
  1322. return $url;
  1323. }
  1324. $route_array = explode("#",$route);
  1325. if(isset($param)&&$param!=''&&!is_array($param))
  1326. {
  1327. $param['id'] = $param;
  1328. }
  1329. $module = strtolower(trim($route_array[0]));
  1330. $action = strtolower(trim($route_array[1]));
  1331. if(!$module||$module=='index')$module="";
  1332. if(!$action||$action=='index')$action="";
  1333. if(app_conf("URL_MODEL")==0)
  1334. {
  1335. //原始模式
  1336. $url = get_domain().REAL_APP_ROOT."/index.php";
  1337. if($module!=''||$action!=''||count($param)>0) //有后缀参数
  1338. {
  1339. $url.="?";
  1340. }
  1341. if($module&&$module!='')
  1342. $url .= "ctl=".$module."&";
  1343. if($action&&$action!='')
  1344. $url .= "act=".$action."&";
  1345. if(count($param)>0)
  1346. {
  1347. foreach($param as $k=>$v)
  1348. {
  1349. if($k&&$v)
  1350. $url =$url.$k."=".urlencode($v)."&";
  1351. }
  1352. }
  1353. if(substr($url,-1,1)=='&'||substr($url,-1,1)=='?') $url = substr($url,0,-1);
  1354. $GLOBALS[$key] = $url;
  1355. set_dynamic_cache($key,$url);
  1356. return $url;
  1357. }
  1358. else
  1359. {
  1360. //重写的默认
  1361. $url = get_domain().REAL_APP_ROOT;
  1362. if($module&&$module!='')
  1363. $url .= "/".$module;
  1364. if($action&&$action!='')
  1365. $url .= "-".$action;
  1366. if(count($param)>0)
  1367. {
  1368. $url.="/";
  1369. foreach($param as $k=>$v)
  1370. {
  1371. $url =$url.$k."-".urlencode($v)."-";
  1372. }
  1373. }
  1374. $route = $module."#".$action;
  1375. switch ($route)
  1376. {
  1377. case "xxx":
  1378. break;
  1379. default:
  1380. break;
  1381. }
  1382. if(substr($url,-1,1)=='/'||substr($url,-1,1)=='-') $url = substr($url,0,-1);
  1383. if($url=='')$url="/";
  1384. $GLOBALS[$key] = $url;
  1385. set_dynamic_cache($key,$url);
  1386. return $url;
  1387. }
  1388. }
  1389. function unicode_encode($name) {//to Unicode
  1390. $name = iconv('UTF-8', 'UCS-2', $name);
  1391. $len = strlen($name);
  1392. $str = '';
  1393. for($i = 0; $i < $len - 1; $i = $i + 2) {
  1394. $c = $name[$i];
  1395. $c2 = $name[$i + 1];
  1396. if (ord($c) > 0) {// 两个字节的字
  1397. $cn_word = '\\'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);
  1398. $str .= strtoupper($cn_word);
  1399. } else {
  1400. $str .= $c2;
  1401. }
  1402. }
  1403. return $str;
  1404. }
  1405. function unicode_decode($name) {//Unicode to
  1406. $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
  1407. preg_match_all($pattern, $name, $matches);
  1408. if (!empty($matches)) {
  1409. $name = '';
  1410. for ($j = 0; $j < count($matches[0]); $j++) {
  1411. $str = $matches[0][$j];
  1412. if (strpos($str, '\\u') === 0) {
  1413. $code = base_convert(substr($str, 2, 2), 16, 10);
  1414. $code2 = base_convert(substr($str, 4), 16, 10);
  1415. $c = chr($code).chr($code2);
  1416. $c = iconv('UCS-2', 'UTF-8', $c);
  1417. $name .= $c;
  1418. } else {
  1419. $name .= $str;
  1420. }
  1421. }
  1422. }
  1423. return $name;
  1424. }
  1425. //载入动态缓存数据
  1426. function load_dynamic_cache($name)
  1427. {
  1428. if(isset($GLOBALS['dynamic_cache'][$name]))
  1429. {
  1430. return $GLOBALS['dynamic_cache'][$name];
  1431. }
  1432. else
  1433. {
  1434. return false;
  1435. }
  1436. }
  1437. function set_dynamic_cache($name,$value)
  1438. {
  1439. if(!isset($GLOBALS['dynamic_cache'][$name]))
  1440. {
  1441. if(count($GLOBALS['dynamic_cache'])>MAX_DYNAMIC_CACHE_SIZE)
  1442. {
  1443. array_shift($GLOBALS['dynamic_cache']);
  1444. }
  1445. $GLOBALS['dynamic_cache'][$name] = $value;
  1446. }
  1447. }
  1448. function load_auto_cache($key,$param=array(),$is_real=true)
  1449. {
  1450. $keys = array('admin_nav','admin_role','api_list','article','article_agreement','article_cates','article_cates_bs','article_notice','article_privacy','banner_list',
  1451. 'cache_nav_list','cate_id','cate_top','index_image','lottery_luckyers','m_config','message_cate','mobile_code','new_hepls','page_image',
  1452. 'pay_list','prop_id','prop_list','region_list','rule_list','score_cates','tipoff_type_list','user_carry_config','user_level','usersig'
  1453. );
  1454. fanwe_require(APP_ROOT_PATH."system/libs/auto_cache.php");
  1455. //if(!in_array($key,$keys)){
  1456. // return false;
  1457. //}
  1458. $file = APP_ROOT_PATH."system/auto_cache/".$key.".auto_cache.php";
  1459. // if(file_exists($file))
  1460. // {
  1461. fanwe_require($file);
  1462. $class = $key."_auto_cache";
  1463. $obj = new $class;
  1464. $result = $obj->load($param,$is_real);
  1465. // }
  1466. // else
  1467. // $result = false;
  1468. return $result;
  1469. }
  1470. function rm_auto_cache($key,$param=array())
  1471. {
  1472. fanwe_require(APP_ROOT_PATH."system/libs/auto_cache.php");
  1473. $file = APP_ROOT_PATH."system/auto_cache/".$key.".auto_cache.php";
  1474. if(file_exists($file))
  1475. {
  1476. fanwe_require($file);
  1477. $class = $key."_auto_cache";
  1478. $obj = new $class;
  1479. $obj->rm($param);
  1480. }
  1481. }
  1482. function clear_auto_cache($key,$param=array())
  1483. {
  1484. fanwe_require(APP_ROOT_PATH."system/libs/auto_cache.php");
  1485. $file = APP_ROOT_PATH."system/auto_cache/".$key.".auto_cache.php";
  1486. if(file_exists($file))
  1487. {
  1488. fanwe_require($file);
  1489. $class = $key."_auto_cache";
  1490. $obj = new $class;
  1491. $obj->clear_all($param);
  1492. }
  1493. }
  1494. function app_login(){
  1495. $agentArr = agentArr();
  1496. $user_info = es_session::get("user_info");
  1497. if(!$user_info){
  1498. $data['is_login'] = 0;
  1499. $data['user_id'] = '';
  1500. $data['nick_name'] = '';
  1501. $data['mobile'] = '';
  1502. }else{
  1503. $data['is_login'] = 1;
  1504. $data['user_id'] = $user_info['id'];
  1505. $data['nick_name'] = $user_info['nick_name'];
  1506. $data['mobile'] = $user_info['mobile'];
  1507. $data['head_image'] = add_domain_url($user_info['head_image']);
  1508. }
  1509. if($agentArr['sdk_type']=="ios"){
  1510. $data['sdk_data']= "weixin://";
  1511. }
  1512. else{
  1513. $data['sdk_data']= "com.tencent.mm";
  1514. }
  1515. return $data;
  1516. }
  1517. /*ajax返回*/
  1518. function ajax_return($data,$r_type=4,$is_debug=false)
  1519. {
  1520. if(!$is_debug){
  1521. header("Content-Type:text/html; charset=utf-8");
  1522. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  1523. filter_null($data);//过滤null
  1524. //过滤false
  1525. $data = filter_all_false($data);
  1526. $encrypt = $GLOBALS['encrypt'];
  1527. $data['act'] = $encrypt['act'];
  1528. $data['ctl'] = $encrypt['ctl'];
  1529. if($encrypt['i_type']){
  1530. ajax_return_aes($data,$r_type);
  1531. }else{
  1532. echo(json_encode($data));
  1533. }
  1534. exit;
  1535. }else{
  1536. var_export($data);
  1537. echo "<br />";
  1538. exit;
  1539. }
  1540. }
  1541. /*admin 后台 ajax返回*/
  1542. function admin_ajax_return($data,$is_debug=false)
  1543. {
  1544. if(!$is_debug){
  1545. header("Content-Type:text/html; charset=utf-8");
  1546. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  1547. filter_null($data);//过滤null
  1548. //过滤false
  1549. echo(json_encode($data));
  1550. exit;
  1551. }else{
  1552. var_export($data);
  1553. echo "<br />";
  1554. exit;
  1555. }
  1556. }
  1557. //过滤null 把null改为空;
  1558. function filter_null(&$request)
  1559. {
  1560. foreach($request as $k=>$v)
  1561. {
  1562. if(is_array($v))
  1563. {
  1564. filter_null($request[$k]);
  1565. }
  1566. else
  1567. {
  1568. if(is_null($v))
  1569. {
  1570. $request[$k] = '';
  1571. }
  1572. }
  1573. }
  1574. }
  1575. /*ajax返回*/
  1576. function ajax_file_return($data,$is_debug=false)
  1577. {
  1578. if(!$is_debug){
  1579. header("Content-Type:text/html; charset=utf-8");
  1580. echo(json_encode($data));
  1581. exit;
  1582. }else{
  1583. if($data['status']==0){
  1584. var_export($data);
  1585. echo "<br />";
  1586. exit;
  1587. }
  1588. }
  1589. }
  1590. /**
  1591. * 过滤绑定用户名中的奇葩字符:替换成可以存入的3字节
  1592. */
  1593. function filterEmoji($string){
  1594. return preg_replace('/[\x{10000}-\x{10FFFF}]/u', '',$string);
  1595. }
  1596. /**
  1597. * 屏蔽Emoji表情:去除4字节的表情
  1598. */
  1599. /*function filterEmoji1($string){
  1600. $str = preg_replace_callback(
  1601. '/./u',
  1602. function (array $match) {
  1603. return strlen($match[0]) >= 4 ? '' : $match[0];
  1604. },
  1605. $str);
  1606. return $str;
  1607. }*/
  1608. function is_animated_gif($filename){
  1609. $fp=fopen($filename, 'rb');
  1610. $filecontent=fread($fp, filesize($filename));
  1611. fclose($fp);
  1612. return strpos($filecontent,chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0')===FALSE?0:1;
  1613. }
  1614. function gen_qrcode($str,$size = 5)
  1615. {
  1616. require_once APP_ROOT_PATH."system/phpqrcode/qrlib.php";
  1617. $root_dir = APP_ROOT_PATH."public/images/qrcode/";
  1618. if (!is_dir($root_dir)) {
  1619. @mkdir($root_dir);
  1620. @chmod($root_dir, 0777);
  1621. }
  1622. $filename = md5($str."|".$size);
  1623. $hash_dir = $root_dir. '/c' . substr(md5($filename), 0, 1)."/";
  1624. if (!is_dir($hash_dir))
  1625. {
  1626. @mkdir($hash_dir);
  1627. @chmod($hash_dir, 0777);
  1628. }
  1629. $filesave = $hash_dir.$filename.'.png';
  1630. if(!file_exists($filesave))
  1631. {
  1632. QRcode::png($str, $filesave, 'Q', $size, 2);
  1633. }
  1634. return APP_ROOT."/public/images/qrcode/c". substr(md5($filename), 0, 1)."/".$filename.".png";
  1635. }
  1636. function format_price($v)
  1637. {
  1638. if(!$v){$v = 0;}
  1639. return "¥".number_format($v,2);
  1640. }
  1641. //发密码验证邮件
  1642. function send_user_password_mail($user_id)
  1643. {
  1644. $verify_code = rand(111111,999999);
  1645. $GLOBALS['db']->query("update ".DB_PREFIX."user set password_verify = '".$verify_code."' where id = ".$user_id);
  1646. $user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$user_id);
  1647. if($user_info)
  1648. {
  1649. $tmpl = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."msg_template where name = 'TPL_MAIL_USER_PASSWORD'");
  1650. $tmpl_content= $tmpl['content'];
  1651. $user_info['logo']=app_conf("SITE_LOGO");
  1652. $user_info['site_name']=app_conf("SITE_NAME");
  1653. $time=get_gmtime();
  1654. $user_info['send_time']=to_date($time,'Y年m月d日');
  1655. $user_info['send_time_ms']=to_date($time,'Y年m月d日 H时i分');
  1656. $user_info['password_url'] = get_domain().url("settings#password", array("code"=>$user_info['password_verify'],"id"=>$user_info['id']));
  1657. $GLOBALS['tmpl']->assign("user",$user_info);
  1658. $msg = $GLOBALS['tmpl']->fetch("str:".$tmpl_content);
  1659. $msg_data['dest'] = $user_info['email'];
  1660. $msg_data['send_type'] = 1;
  1661. $msg_data['title'] = "重置密码";
  1662. $msg_data['content'] = addslashes($msg);
  1663. $msg_data['send_time'] = 0;
  1664. $msg_data['is_send'] = 0;
  1665. $msg_data['create_time'] = get_gmtime();
  1666. $msg_data['user_id'] = $user_info['id'];
  1667. $msg_data['is_html'] = $tmpl['is_html'];
  1668. $GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); //插入
  1669. }
  1670. }
  1671. function strim($str)
  1672. {
  1673. return quotes(htmlspecialchars(trim($str)));
  1674. }
  1675. function btrim($str)
  1676. {
  1677. return quotes(trim($str));
  1678. }
  1679. function valid_tag($str)
  1680. {
  1681. return preg_replace("/<(?!div|ol|ul|li|sup|sub|span|br|img|p|h1|h2|h3|h4|h5|h6|\/div|\/ol|\/ul|\/li|\/sup|\/sub|\/span|\/br|\/img|\/p|\/h1|\/h2|\/h3|\/h4|\/h5|\/h6|blockquote|\/blockquote|strike|\/strike|b|\/b|i|\/i|u|\/u)[^>]*>/i","",$str);
  1682. }
  1683. //$type = 1(添加) 2(删除)
  1684. function update_user_weibo($user_id,$weibo_url,$type=1)
  1685. {
  1686. if($weibo_url!="")
  1687. {
  1688. if($type==1)
  1689. {
  1690. if($GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user_weibo where weibo_url = '".$weibo_url."' and user_id = ".$user_id)==0)
  1691. {
  1692. $weibo_data['user_id'] = $user_id;
  1693. $weibo_data['weibo_url'] = $weibo_url;
  1694. $GLOBALS['db']->autoExecute(DB_PREFIX."user_weibo",$weibo_data);
  1695. }
  1696. }
  1697. if($type==2)
  1698. {
  1699. $GLOBALS['db']->query("delete from ".DB_PREFIX."user_weibo where user_id = ".$user_id." and weibo_url = '".$weibo_url."'");
  1700. }
  1701. }
  1702. }
  1703. //同步到微博
  1704. function syn_weibo($data)
  1705. {
  1706. $api_list = $GLOBALS['db']->getAllCached("select * from ".DB_PREFIX."api_login where is_weibo = 1");
  1707. foreach($api_list as $k=>$v)
  1708. {
  1709. if($GLOBALS['user_info'][strtolower($v['class_name'])."_id"]==""||$GLOBALS['user_info'][strtolower($v['class_name'])."_token"]=="")
  1710. {
  1711. unset($api_list[$k]);
  1712. }
  1713. else
  1714. {
  1715. $class_name = $v['class_name']."_api";
  1716. require_once APP_ROOT_PATH."system/api_login/".$class_name.".php";
  1717. $o = new $class_name($v);
  1718. $o->send_message($data);
  1719. }
  1720. }
  1721. }
  1722. function check_sms_send($mobile){
  1723. $data = array();
  1724. $data['status'] = 1;
  1725. $data['error'] = "未定义限制";
  1726. /*
  1727. if(!SMS_MOBILE_SEND_COUNT&&!SMS_IP_SEND_COUNT){
  1728. //return false;
  1729. $data['status'] = 1;
  1730. $data['error'] = "未定义限制";
  1731. }*/
  1732. $now_ip = get_client_ip();
  1733. $now_date = to_date(get_gmtime(),'Y-m-d');
  1734. //$now_date = to_timespan($now_date);
  1735. //$to_date = $now_date + 24*3600;
  1736. if (defined('SMS_MOBILE_SEND_COUNT') && SMS_MOBILE_SEND_COUNT > 0){
  1737. $mobile_sql = "select count(*) from ".DB_PREFIX."deal_msg_list where send_type = 0 and dest = '".$mobile."' and send_date ='".$now_date."'";
  1738. $mobile_count = $GLOBALS['db']->getOne($mobile_sql);
  1739. $mobile_count = intval($mobile_count);
  1740. if($mobile_count>SMS_MOBILE_SEND_COUNT){
  1741. $data['status'] = 0;
  1742. $data['error'] = "验证码发送失败,当前手机号已超过今天限额";
  1743. }
  1744. }
  1745. if ($data['status'] == 1 && defined('SMS_IP_SEND_COUNT') && SMS_IP_SEND_COUNT > 0){
  1746. $date_h = to_date(get_gmtime(),'H');
  1747. $ip_sql = "select count(*) from ".DB_PREFIX."deal_msg_list where send_type = 0 and client_ip ='".$now_ip."' and send_h = ".$date_h." and send_date ='".$now_date."'";
  1748. $ip_count = $GLOBALS['db']->getOne($ip_sql);
  1749. $ip_count = intval($ip_count);
  1750. if($ip_count>SMS_IP_SEND_COUNT){
  1751. $data['status'] = 0;
  1752. $data['error'] = "验证码发送失败,当前ip已超过今天限额";
  1753. }
  1754. }
  1755. return $data;
  1756. }
  1757. //发短信验证码
  1758. function send_verify_sms($mobile,$code,$type="")
  1759. {
  1760. $type ='sms';
  1761. $dest = $mobile;
  1762. $title='';
  1763. /*
  1764. * 发送验证码
  1765. */
  1766. $user_info = array();
  1767. if(!empty($dest)){
  1768. $user_info = $GLOBALS['db']->getRow("select *,id as user_id from ".DB_PREFIX."user where mobile='".$dest."'");
  1769. $user_info['mobile'] = $dest;
  1770. $user_info['code'] = $code;
  1771. $user_info['tmpl_sms_name'] = 'verify';
  1772. if($title){
  1773. $msg_data['title'] = $title;
  1774. }else{
  1775. $msg_data['title'] = "短信验证码";
  1776. }
  1777. $msg_data['dest'] = $user_info['mobile'];
  1778. $msg_data['user_id'] = $user_info['user_id'];
  1779. $msg_data['is_html'] = 0;
  1780. $msg_data['send_type'] = 0;
  1781. $msg_data['code'] =$code;
  1782. if(app_conf("SMS_ON")!=1&&$type=='sms'){
  1783. return false;
  1784. }
  1785. $tmpl = $GLOBALS['db']->getRowCached("select * from ".DB_PREFIX."msg_template where name = 'TPL_SMS_VERIFY_CODE'");
  1786. //$tmpl = str_replace('{$verify.mobile}',$dest,$tmpl);
  1787. //补充 替换verify.mobile
  1788. $tmpl = str_replace('你的手机号为{$verify.mobile},','',$tmpl);
  1789. $tmpl['content'] = str_replace('{$verify.code}',$code,$tmpl);
  1790. $msg= $tmpl['content'];
  1791. $msg_data['send_type'] = 0;
  1792. $msg_data['content'] = addslashes($msg['content']);
  1793. $msg_data['send_time'] = 0;
  1794. $msg_data['is_send'] = 0;
  1795. $msg_data['create_time'] = get_gmtime();
  1796. $msg_data['is_html'] = 1;
  1797. $msg_data['client_ip'] = get_client_ip();
  1798. $msg_data['send_date'] = to_date(get_gmtime(),'Y-m-d');
  1799. $msg_data['send_h'] = to_date(get_gmtime(),'H');
  1800. if($msg_data){
  1801. $data = $msg_data;
  1802. if(app_conf('IS_SMS_DIRECT')==1){
  1803. if($data['send_type']==0){
  1804. require_once APP_ROOT_PATH."system/utils/es_sms.php";
  1805. $sms = new sms_sender();
  1806. $result = $sms->sendSms($data['dest'],$data['content']);
  1807. $data['is_success'] = intval($result['status']);
  1808. $data['result'] = $result['msg'];
  1809. }
  1810. $data['is_send'] = 1;
  1811. $data['send_time'] = get_gmtime();
  1812. }
  1813. return $GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$data); //插入
  1814. }
  1815. }
  1816. }
  1817. /**
  1818. * 发送投资通短信验证码
  1819. * @param $mobile 手机号
  1820. * @param $code 验证码
  1821. */
  1822. function send_tzt_verify_sms($mobile, $code){
  1823. $GLOBALS['msg']->manage_msg('TPL_SMS_TZT_VERIFY_CODE',$mobile,array('code'=>$code,'user_id'=>$GLOBALS['user_info']['id']));
  1824. }
  1825. //发邮件验证码
  1826. function send_verify_email($email,$code,$title="")
  1827. {
  1828. $GLOBALS['msg']->manage_msg('TPL_MAIL_USER_VERIFY',$email,array('code'=>$code,'title'=>$title));
  1829. }
  1830. //获取系统运行上传的值
  1831. function get_max_file_size(){
  1832. $system_size=intval(ini_get("post_max_size"))<intval(ini_get("upload_max_filesize"))?intval(ini_get("post_max_size"))*1024*1024:intval(ini_get("upload_max_filesize"))*1024*1024;
  1833. $config_size=app_conf("MAX_IMAGE_SIZE");
  1834. $max_size = $system_size>$config_size?$config_size:$system_size;
  1835. //number_format($system_size/(1024*1024),1)
  1836. if($max_size>=1024*1024){
  1837. return number_format($max_size/(1024*1024),1).'MB';
  1838. }elseif($max_size>=1024){
  1839. return number_format($max_size/(1024),1).'KB';
  1840. }else{
  1841. return $max_size.'B';
  1842. }
  1843. }
  1844. //获取系统运行上传的值
  1845. function get_max_file_size_byte(){
  1846. $system_size=intval(ini_get("post_max_size"))<intval(ini_get("upload_max_filesize"))?intval(ini_get("post_max_size"))*1024*1024:intval(ini_get("upload_max_filesize"))*1024*1024;
  1847. $config_size=app_conf("MAX_IMAGE_SIZE");
  1848. $max_size = $system_size>$config_size?$config_size:$system_size;
  1849. return $max_size;
  1850. }
  1851. function isMobile() {
  1852. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  1853. if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){
  1854. return true;
  1855. }
  1856. //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  1857. if (isset ($_SERVER['HTTP_VIA'])) {
  1858. //找不到为flase,否则为true
  1859. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  1860. }
  1861. //判断手机发送的客户端标志,兼容性有待提高
  1862. if (isset ($_SERVER['HTTP_USER_AGENT'])) {
  1863. $clientkeywords = array (
  1864. 'nokia',
  1865. 'sony',
  1866. 'ericsson',
  1867. 'mot',
  1868. 'samsung',
  1869. 'htc',
  1870. 'sgh',
  1871. 'lg',
  1872. 'sharp',
  1873. 'sie-',
  1874. 'philips',
  1875. 'panasonic',
  1876. 'alcatel',
  1877. 'lenovo',
  1878. 'iphone',
  1879. 'ipod',
  1880. 'blackberry',
  1881. 'meizu',
  1882. 'android',
  1883. 'netfront',
  1884. 'symbian',
  1885. 'ucweb',
  1886. 'windowsce',
  1887. 'palm',
  1888. 'operamini',
  1889. 'operamobi',
  1890. 'openwave',
  1891. 'nexusone',
  1892. 'cldc',
  1893. 'midp',
  1894. 'wap',
  1895. 'mobile'
  1896. );
  1897. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  1898. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
  1899. return true;
  1900. }
  1901. }
  1902. //协议法,因为有可能不准确,放到最后判断
  1903. if (isset ($_SERVER['HTTP_ACCEPT'])) {
  1904. // 如果只支持wml并且不支持html那一定是移动设备
  1905. // 如果支持wml和html但是wml在html之前则是移动设备
  1906. if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
  1907. return true;
  1908. }
  1909. }
  1910. }
  1911. //发起通知用户审核通过或者失败
  1912. function send_investor_status($user_info){
  1913. if($user_info['id']){
  1914. $GLOBALS['msg']->manage_msg("MSG_INVEST_STATUS",$user_info['id'],array('user_info'=>$user_info));
  1915. }
  1916. }
  1917. function get_investor($is_investor){
  1918. switch($is_investor){
  1919. case 0:
  1920. return '普通会员';
  1921. break;
  1922. case 1:
  1923. return '企业会员';
  1924. break;
  1925. /*case 2:
  1926. return '投资机构';
  1927. break;*/
  1928. }
  1929. }
  1930. function get_investor_status($investor_status){
  1931. switch($investor_status){
  1932. case 0:
  1933. return '未审核';
  1934. break;
  1935. case 1:
  1936. return '待审核';
  1937. break;
  1938. case 2:
  1939. return '审核通过';
  1940. break;
  1941. case 3:
  1942. return '审核未通过';
  1943. break;
  1944. }
  1945. }
  1946. function LOGIN_DES_KEY(){
  1947. if(!es_session::is_set("DES_KEY")){
  1948. require_once APP_ROOT_PATH."system/utils/es_string.php";
  1949. es_session::set("DES_KEY",es_string::rand_string(50));
  1950. }
  1951. return es_session::get("DES_KEY");
  1952. }
  1953. //检测手机是否可以绑定
  1954. function check_registor_mobile($check_mobile_info,$ajax=1){
  1955. $mobile = $check_mobile_info['mobile'];
  1956. $login_type = $check_mobile_info['login_type'];
  1957. if(strlen($mobile)< 0 || strlen($mobile)== 0){
  1958. $data['status'] = 0;
  1959. $data['info'] = '请输入手机号码';
  1960. ajax_return($data);
  1961. }
  1962. if(!check_mobile($mobile))
  1963. {
  1964. $data['status'] = 0;
  1965. $data['info'] = '请填写正确的手机号码';
  1966. ajax_return($data);
  1967. }
  1968. if(strlen($mobile)>11){
  1969. $data['status'] = 0;
  1970. $data['info'] = '"手机号码长度不能超过11位';
  1971. ajax_return($data);
  1972. }
  1973. $condition=" mobile ='".$mobile."' and login_type=".$login_type;
  1974. $num=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user where $condition");
  1975. if($num>0){
  1976. $data['status'] = 0;
  1977. $data['info'] = '手机已存在,请重新输入';
  1978. ajax_return($data);
  1979. }
  1980. }
  1981. //检测手机是否可以绑定
  1982. function check_registor_email($email,$ajax=1){
  1983. if(strlen($email)<=0 ){
  1984. showErr("请输入邮箱",$ajax,"");
  1985. }
  1986. if(!check_email($email))
  1987. {
  1988. showErr("请填写正确的邮箱",$ajax,"");
  1989. }
  1990. $condition=" email='$email'";
  1991. $num=$GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user where $condition");
  1992. if($num>0){
  1993. showErr("邮箱已存在,请重新输入",$ajax,"");
  1994. }
  1995. }
  1996. /**
  1997. * 验证身份证号
  1998. * @param $vStr
  1999. * @return bool
  2000. */
  2001. function isCreditNo($vStr)
  2002. {
  2003. $vCity = array(
  2004. '11','12','13','14','15','21','22',
  2005. '23','31','32','33','34','35','36',
  2006. '37','41','42','43','44','45','46',
  2007. '50','51','52','53','54','61','62',
  2008. '63','64','65','71','81','82','91'
  2009. );
  2010. if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
  2011. if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
  2012. $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
  2013. $vLength = strlen($vStr);
  2014. if ($vLength == 18)
  2015. {
  2016. $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
  2017. } else {
  2018. $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
  2019. }
  2020. if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
  2021. if ($vLength == 18)
  2022. {
  2023. $vSum = 0;
  2024. for ($i = 17 ; $i >= 0 ; $i--)
  2025. {
  2026. $vSubStr = substr($vStr, 17 - $i, 1);
  2027. $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
  2028. }
  2029. if($vSum % 11 != 1) return false;
  2030. }
  2031. return true;
  2032. }
  2033. //获取来源网站
  2034. function set_source_url(){
  2035. if(!es_session::get("source_url")&&!$GLOBALS['user_info']){
  2036. if($_SERVER['HTTP_REFERER']){
  2037. $source_url=$_SERVER['HTTP_REFERER'];
  2038. $url=parse_url($source_url);
  2039. if($url['host']!=$_SERVER['HTTP_HOST']){
  2040. es_session::set("source_url",$url['host']);
  2041. }
  2042. }
  2043. }
  2044. }
  2045. function get_http()
  2046. {
  2047. return (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
  2048. }
  2049. function get_domain()
  2050. {
  2051. /* 协议 */
  2052. $protocol = get_http();
  2053. if(app_conf("SITE_DOMAIN")!="")
  2054. {
  2055. return $protocol.app_conf("SITE_DOMAIN");
  2056. }
  2057. /* 域名或IP地址 */
  2058. if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
  2059. {
  2060. $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
  2061. }
  2062. elseif (isset($_SERVER['HTTP_HOST']))
  2063. {
  2064. $host = $_SERVER['HTTP_HOST'];
  2065. }
  2066. else
  2067. {
  2068. /* 端口 */
  2069. if (isset($_SERVER['SERVER_PORT']))
  2070. {
  2071. $port = ':' . $_SERVER['SERVER_PORT'];
  2072. if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol))
  2073. {
  2074. $port = '';
  2075. }
  2076. }
  2077. else
  2078. {
  2079. $port = '';
  2080. }
  2081. if (isset($_SERVER['SERVER_NAME']))
  2082. {
  2083. $host = $_SERVER['SERVER_NAME'] . $port;
  2084. }
  2085. elseif (isset($_SERVER['SERVER_ADDR']))
  2086. {
  2087. $host = $_SERVER['SERVER_ADDR'] . $port;
  2088. }
  2089. }
  2090. return $protocol . $host;
  2091. }
  2092. function get_host()
  2093. {
  2094. /* 域名或IP地址 */
  2095. if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
  2096. {
  2097. $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
  2098. }
  2099. elseif (isset($_SERVER['HTTP_HOST']))
  2100. {
  2101. $host = $_SERVER['HTTP_HOST'];
  2102. }
  2103. else
  2104. {
  2105. if (isset($_SERVER['SERVER_NAME']))
  2106. {
  2107. $host = $_SERVER['SERVER_NAME'];
  2108. }
  2109. elseif (isset($_SERVER['SERVER_ADDR']))
  2110. {
  2111. $host = $_SERVER['SERVER_ADDR'];
  2112. }
  2113. }
  2114. return $host;
  2115. }
  2116. /**
  2117. * 将单个图片同步到远程的图片服务器
  2118. * @param string $url 本地的图片地址,"./public/......"
  2119. */
  2120. function syn_to_remote_image_server($url,$is_unlink=true)
  2121. {
  2122. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  2123. {
  2124. if($GLOBALS['distribution_cfg']['OSS_TYPE']=="ES_FILE")
  2125. {
  2126. $pathinfo = pathinfo($url);
  2127. $file = $pathinfo['basename'];
  2128. $dir = $pathinfo['dirname'];
  2129. $dir = str_replace("./public/", "", $dir);
  2130. $filefull = SITE_DOMAIN.APP_ROOT."/public/".$dir."/".$file;
  2131. $syn_url = $GLOBALS['distribution_cfg']['OSS_DOMAIN']."/es_file.php?username=".$GLOBALS['distribution_cfg']['OSS_ACCESS_ID']."&password=".$GLOBALS['distribution_cfg']['OSS_ACCESS_KEY']."&file=".
  2132. $filefull."&path=".$dir."/&name=".$file."&act=0";
  2133. @file_get_contents($syn_url);
  2134. }
  2135. elseif($GLOBALS['distribution_cfg']['OSS_TYPE']=="ALI_OSS")
  2136. {
  2137. $pathinfo = pathinfo($url);
  2138. $file = $pathinfo['basename'];
  2139. $dir = $pathinfo['dirname'];
  2140. $dir = str_replace("./public/", "public/", $dir);
  2141. require_once APP_ROOT_PATH."system/alioss/sdk.class.php";
  2142. $oss_sdk_service = new ALIOSS();
  2143. //设置是否打开curl调试模式
  2144. $oss_sdk_service->set_debug_mode(FALSE);
  2145. $bucket = $GLOBALS['distribution_cfg']['OSS_BUCKET_NAME'];
  2146. $object = $dir."/".$file;
  2147. $file_path = APP_ROOT_PATH.$dir."/".$file;
  2148. $oss_sdk_service->upload_file_by_file($bucket,$object,$file_path);
  2149. if($is_unlink&&intval($GLOBALS['distribution_cfg']['OSS_NO_SAVE_LOCALHOST'])==0){
  2150. $info = (array)$oss_sdk_service->is_object_exist($bucket,$object);
  2151. if(file_exists($file_path)&&$info['status']==200)unlink($file_path);
  2152. }
  2153. }
  2154. }
  2155. }
  2156. function format_image_path($out)
  2157. {
  2158. //对图片路径的修复
  2159. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  2160. {
  2161. $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
  2162. }
  2163. else
  2164. {
  2165. $domain = SITE_DOMAIN.APP_ROOT;
  2166. }
  2167. $out = str_replace(APP_ROOT."./public/",$domain."/public/",$out);
  2168. $out = str_replace("./public/",$domain."/public/",$out);
  2169. return $out;
  2170. }
  2171. function replace_public($str){
  2172. //对图片路径的修复
  2173. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  2174. {
  2175. $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
  2176. }
  2177. else
  2178. {
  2179. $domain = SITE_DOMAIN.APP_ROOT;
  2180. }
  2181. return str_replace($domain."/public/","./public/",$str);
  2182. }
  2183. /**
  2184. * 同步脚本样式缓存 $url:'public/runtime/statics/biz/'.$url.'.css';
  2185. * @param unknown_type $url
  2186. */
  2187. function syn_to_remote_file_server($url)
  2188. {
  2189. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  2190. {
  2191. if($GLOBALS['distribution_cfg']['OSS_TYPE']=="ES_FILE")
  2192. {
  2193. $pathinfo = pathinfo($url);
  2194. $file = $pathinfo['basename'];
  2195. $dir = $pathinfo['dirname'];
  2196. $dir = str_replace("public/", "", $dir);
  2197. $filefull = SITE_DOMAIN.APP_ROOT."/public/".$dir."/".$file;
  2198. $syn_url = $GLOBALS['distribution_cfg']['OSS_DOMAIN']."/es_file.php?username=".$GLOBALS['distribution_cfg']['OSS_ACCESS_ID']."&password=".$GLOBALS['distribution_cfg']['OSS_ACCESS_KEY']."&file=".
  2199. $filefull."&path=".$dir."/&name=".$file."&act=0";
  2200. @file_get_contents($syn_url);
  2201. }
  2202. elseif($GLOBALS['distribution_cfg']['OSS_TYPE']=="ALI_OSS")
  2203. {
  2204. $pathinfo = pathinfo($url);
  2205. $file = $pathinfo['basename'];
  2206. $dir = $pathinfo['dirname'];
  2207. require_once APP_ROOT_PATH."system/alioss/sdk.class.php";
  2208. $oss_sdk_service = new ALIOSS();
  2209. //设置是否打开curl调试模式
  2210. $oss_sdk_service->set_debug_mode(FALSE);
  2211. $bucket = $GLOBALS['distribution_cfg']['OSS_BUCKET_NAME'];
  2212. $object = $dir."/".$file;
  2213. $file_path = APP_ROOT_PATH.$dir."/".$file;
  2214. $oss_sdk_service->upload_file_by_file($bucket,$object,$file_path);
  2215. }
  2216. }
  2217. }
  2218. function isWeixin(){
  2219. $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  2220. $is_weixin = strpos($agent, 'micromessenger') ? true : false ;
  2221. if($is_weixin){
  2222. return true;
  2223. }else{
  2224. return false;
  2225. }
  2226. }
  2227. function isios() {
  2228. //判断手机发送的客户端标志,兼容性有待提高
  2229. if (isset ($_SERVER['HTTP_USER_AGENT'])) {
  2230. $clientkeywords = array (
  2231. 'iphone',
  2232. 'ipod',
  2233. 'mac',
  2234. );
  2235. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  2236. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
  2237. return true;
  2238. }
  2239. }
  2240. }
  2241. //显示成功
  2242. function showIpsInfo($msg,$jump='')
  2243. {
  2244. $GLOBALS['tmpl']->assign('msg',$msg);
  2245. $GLOBALS['tmpl']->assign('jump',$jump);
  2246. $GLOBALS['tmpl']->display("ips_show.html");
  2247. exit;
  2248. }
  2249. //日期加减
  2250. function dec_date($date,$dec){
  2251. //$sysc_start_time = to_timespan(to_date(to_timespan($date),'Y-m-d')) - $dec * 86400;
  2252. return to_date(to_timespan($date) - $dec * 86400,'Y-m-d');
  2253. }
  2254. /**
  2255. * 作用:将xml转为array
  2256. */
  2257. function xmlToArray($xml)
  2258. {
  2259. //将XML转为array
  2260. $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  2261. return $array_data;
  2262. }
  2263. /**
  2264. * 作用:array转xml
  2265. */
  2266. function arrayToXml($arr)
  2267. {
  2268. $xml = "<xml>";
  2269. foreach ($arr as $key=>$val)
  2270. {
  2271. if (is_numeric($val))
  2272. {
  2273. $xml.="<".$key.">".$val."</".$key.">";
  2274. }
  2275. else
  2276. $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
  2277. }
  2278. $xml.="</xml>";
  2279. return $xml;
  2280. }
  2281. function log_result($word)
  2282. {
  2283. if (is_array($word)) $word = var_export($word,true);
  2284. $file = APP_ROOT_PATH."/public/notify_url.log";
  2285. $fp = fopen($file,"a");
  2286. flock($fp, LOCK_EX) ;
  2287. fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
  2288. flock($fp, LOCK_UN);
  2289. fclose($fp);
  2290. }
  2291. function log_result_wx($word)
  2292. {
  2293. if (is_array($word)) $word = var_export($word,true);
  2294. $file = APP_ROOT_PATH."/public/notify_url_wx.log";
  2295. $fp = fopen($file,"a");
  2296. flock($fp, LOCK_EX) ;
  2297. fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
  2298. flock($fp, LOCK_UN);
  2299. fclose($fp);
  2300. }
  2301. function log_result_wx_pay_log($word)
  2302. {
  2303. if (!is_dir(APP_ROOT_PATH."public/wx_pay_log")) {
  2304. @mkdir(APP_ROOT_PATH."public/wx_pay_log");
  2305. }
  2306. $file = APP_ROOT_PATH."/public/wx_pay_log/".to_date(get_gmtime()-604800,"Ymd").".log";
  2307. if(file_exists($file)){
  2308. unlink($file);
  2309. }
  2310. $filename = to_date(get_gmtime(),"Ymd");
  2311. if (is_array($word)) $word = var_export($word,true);
  2312. $file = APP_ROOT_PATH."/public/wx_pay_log/".$filename.".log";
  2313. $fp = fopen($file,"a");
  2314. flock($fp, LOCK_EX) ;
  2315. fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
  2316. flock($fp, LOCK_UN);
  2317. fclose($fp);
  2318. }
  2319. /**
  2320. * 分页处理
  2321. * @param string $type 所在页面
  2322. * @param array $args 参数
  2323. * @param int $total_count 总数
  2324. * @param int $page 当前页
  2325. * @param int $page_size 分页大小
  2326. * @param string $url 自定义路径
  2327. * @param int $offset 偏移量
  2328. * @return array
  2329. */
  2330. function buildPage($type,$args,$total_count,$page = 1,$page_size = 0,$url='',$offset = 5){
  2331. $pager['total_count'] = intval($total_count);
  2332. $pager['page'] = $page;
  2333. $pager['page_size'] = ($page_size == 0) ? 20 : $page_size;
  2334. /* page 总数 */
  2335. $pager['page_count'] = ($pager['total_count'] > 0) ? ceil($pager['total_count'] / $pager['page_size']) : 1;
  2336. /* 边界处理 */
  2337. if ($pager['page'] > $pager['page_count'])
  2338. $pager['page'] = $pager['page_count'];
  2339. $pager['limit'] = ($pager['page'] - 1) * $pager['page_size'] . "," . $pager['page_size'];
  2340. $page_prev = ($pager['page'] > 1) ? $pager['page'] - 1 : 1;
  2341. $page_next = ($pager['page'] < $pager['page_count']) ? $pager['page'] + 1 : $pager['page_count'];
  2342. $pager['prev_page'] = $page_prev;
  2343. $pager['next_page'] = $page_next;
  2344. if (!empty($url)){
  2345. $pager['page_first'] = $url . 1;
  2346. $pager['page_prev'] = $url . $page_prev;
  2347. $pager['page_next'] = $url . $page_next;
  2348. $pager['page_last'] = $url . $pager['page_count'];
  2349. }
  2350. else{
  2351. $args['page'] = '_page_';
  2352. if(!empty($type)){
  2353. if(strpos($type,'javascript:') === false){
  2354. //$page_url = JKU($type,$args);
  2355. $page_url = u($type,$args);
  2356. }else{
  2357. $page_url = $type;
  2358. }
  2359. }else{
  2360. $page_url = 'javascript:;';
  2361. }
  2362. $pager['page_first'] = str_replace('_page_',1,$page_url);
  2363. $pager['page_prev'] = str_replace('_page_',$page_prev,$page_url);
  2364. $pager['page_next'] = str_replace('_page_',$page_next,$page_url);
  2365. $pager['page_last'] = str_replace('_page_',$pager['page_count'],$page_url);
  2366. }
  2367. $pager['page_nums'] = array();
  2368. if($pager['page_count'] <= $offset * 2){
  2369. for ($i=1; $i <= $pager['page_count']; $i++){
  2370. $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
  2371. }
  2372. }else{
  2373. if($pager['page'] - $offset < 2){
  2374. $temp = $offset * 2;
  2375. for ($i=1; $i<=$temp; $i++){
  2376. $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
  2377. }
  2378. $pager['page_nums'][] = array('name'=>'...');
  2379. $pager['page_nums'][] = array('name' => $pager['page_count'],'url' => empty($url) ? str_replace('_page_',$pager['page_count'],$page_url) : $url . $pager['page_count']);
  2380. }else{
  2381. $pager['page_nums'][] = array('name' => 1,'url' => empty($url) ? str_replace('_page_',1,$page_url) : $url . 1);
  2382. $pager['page_nums'][] = array('name'=>'...');
  2383. $start = $pager['page'] - $offset + 1;
  2384. $end = $pager['page'] + $offset - 1;
  2385. if($pager['page_count'] - $end > 1){
  2386. for ($i=$start;$i<=$end;$i++){
  2387. $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
  2388. }
  2389. $pager['page_nums'][] = array('name'=>'...');
  2390. $pager['page_nums'][] = array('name' => $pager['page_count'],'url' => empty($url) ? str_replace('_page_',$pager['page_count'],$page_url) : $url . $pager['page_count']);
  2391. }else{
  2392. $start = $pager['page_count'] - $offset * 2 + 1;
  2393. $end = $pager['page_count'];
  2394. for ($i=$start;$i<=$end;$i++){
  2395. $pager['page_nums'][] = array('name' => $i,'url' => empty($url) ? str_replace('_page_',$i,$page_url) : $url . $i);
  2396. }
  2397. }
  2398. }
  2399. }
  2400. return $pager;
  2401. }
  2402. function parse_url_tag_coomon($str)
  2403. {
  2404. $str = substr($str,2);
  2405. $str_array = explode("|",$str);
  2406. $route = $str_array[0];
  2407. $param_tmp = explode("&",$str_array[1]);
  2408. $param = array();
  2409. foreach($param_tmp as $item)
  2410. {
  2411. if($item!='')
  2412. $item_arr = explode("=",$item);
  2413. if($item_arr[0]&&$item_arr[1])
  2414. $param[$item_arr[0]] = $item_arr[1];
  2415. }
  2416. return url($route,$param);
  2417. }
  2418. //解析URL标签
  2419. // $str = u:acate#index|id=10&name=abc
  2420. function parse_url_tag($str)
  2421. {
  2422. $key = md5("URL_TAG_".$str);
  2423. if(isset($GLOBALS[$key]))
  2424. {
  2425. return $GLOBALS[$key];
  2426. }
  2427. $url = load_dynamic_cache($key);
  2428. if($url!==false)
  2429. {
  2430. $GLOBALS[$key] = $url;
  2431. return $url;
  2432. }
  2433. $str = substr($str,2);
  2434. $str_array = explode("|",$str);
  2435. $route = $str_array[0];
  2436. $param_tmp = explode("&",$str_array[1]);
  2437. $param = array();
  2438. foreach($param_tmp as $item)
  2439. {
  2440. if($item!='')
  2441. $item_arr = explode("=",$item);
  2442. if($item_arr[0]&&$item_arr[1])
  2443. $param[$item_arr[0]] = $item_arr[1];
  2444. }
  2445. $GLOBALS[$key]= url($route,$param);
  2446. set_dynamic_cache($key,$GLOBALS[$key]);
  2447. return $GLOBALS[$key];
  2448. }
  2449. function parse_url_tag_wap($str)
  2450. {
  2451. $key = md5("URL_TAG_".$str);
  2452. if(isset($GLOBALS[$key]))
  2453. {
  2454. return $GLOBALS[$key];
  2455. }
  2456. $url = load_dynamic_cache($key);
  2457. if($url!==false)
  2458. {
  2459. $GLOBALS[$key] = $url;
  2460. return $url;
  2461. }
  2462. $str = substr($str,2);
  2463. $str_array = explode("|",$str);
  2464. $route = $str_array[0];
  2465. $param_tmp = explode("&",$str_array[1]);
  2466. $param = array();
  2467. foreach($param_tmp as $item)
  2468. {
  2469. if($item!='')
  2470. $item_arr = explode("=",$item);
  2471. if($item_arr[0]&&$item_arr[1])
  2472. $param[$item_arr[0]] = $item_arr[1];
  2473. }
  2474. $GLOBALS[$key]= url_wap($route,$param);
  2475. set_dynamic_cache($key,$GLOBALS[$key]);
  2476. return $GLOBALS[$key];
  2477. }
  2478. function HASH_KEY(){
  2479. if(!es_session::is_set("HASH_KEY")){
  2480. require_once APP_ROOT_PATH."system/utils/es_string.php";
  2481. es_session::set("HASH_KEY",es_string::rand_string(50));
  2482. }
  2483. return es_session::get("HASH_KEY");
  2484. }
  2485. function check_hash_key(){
  2486. if(strim($_REQUEST['fhash'])!="" && md5(HASH_KEY())==md5($_REQUEST['fhash'])){
  2487. return true;
  2488. }
  2489. else
  2490. return false;
  2491. }
  2492. function number_price_format($price)
  2493. {
  2494. if($price*100%100==0)
  2495. $price= number_format(round($price,2));
  2496. else
  2497. $price = number_format(round($price,2),2);
  2498. return $price;
  2499. }
  2500. /** 获取当前时间戳,精确到毫秒 */
  2501. function microtime_float()
  2502. {
  2503. list($usec, $sec) = explode(" ", microtime());
  2504. return ((float)$usec + (float)$sec-date('Z'));
  2505. }
  2506. /** 格式化时间戳,精确到毫秒,x代表毫秒 */
  2507. function microtime_format($utc_time, $format = 'H:i:s.x')
  2508. {
  2509. if (empty ( $utc_time )) {
  2510. return '';
  2511. }
  2512. $timezone = intval(app_conf('TIME_ZONE'));
  2513. $time = $utc_time + $timezone * 3600;
  2514. list($usec, $sec) = explode(".", $time);
  2515. $date = date($format,$usec);
  2516. return str_replace('x', $sec, $date);
  2517. }
  2518. function trim_utf8mb4($str){
  2519. return preg_replace('/[\x{10000}-\x{10FFFF}]/u', '',$str);
  2520. }
  2521. /**
  2522. * 只保留字符串首尾字符,隐藏中间用*代替(两个字符时只显示第一个)
  2523. * @param string $user_name 姓名
  2524. * @return string 格式化后的姓名
  2525. */
  2526. function substr_cut($user_name){
  2527. $strlen = mb_strlen($user_name, 'utf-8');
  2528. $firstStr = mb_substr($user_name, 0, 1, 'utf-8');
  2529. $lastStr = mb_substr($user_name, -1, 1, 'utf-8');
  2530. return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
  2531. }
  2532. /*
  2533. * is_wap 0 表示wep 1表示wap 2表示APP
  2534. */
  2535. function create_target_url($target,$is_wap = 0,$cart_id=''){
  2536. $return_url = "";
  2537. if(strpos($target,'URL-dealID-')!==FALSE){
  2538. $deal_id = trim($target,'URL-dealID-');
  2539. if($cart_id!=''){
  2540. $id = trim($cart_id,'URL-cartID-');
  2541. }
  2542. if($is_wap==0){
  2543. $return_url = url("deal#show",array('id'=>$deal_id));
  2544. }elseif($is_wap==1){
  2545. if($id){
  2546. $return_url = url_wap("cart#index",array('id'=>$id,'deal_id'=>$deal_id));
  2547. }else{
  2548. $return_url = url_wap("deal#show",array('id'=>$deal_id));
  2549. }
  2550. }
  2551. }
  2552. return $return_url;
  2553. }
  2554. //验证网址
  2555. function check_url($url)
  2556. {
  2557. $patern ='/^http[s]?:\/\/'.
  2558. '(([0-9]{1,3}\.){3}[0-9]{1,3}'. // IP形式的URL- 199.194.52.184
  2559. '|'. // 允许IP和DOMAIN(域名)
  2560. '([0-9a-z_!~*\'()-]+\.)*'. // 域名- www.
  2561. '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.'. // 二级域名
  2562. '[a-z]{2,6})'. // first level domain- .com or .museum
  2563. '(:[0-9]{1,4})?'. // 端口- :80
  2564. '((\/\?)|'. // a slash isn't required if there is no file name
  2565. '(\/[0-9a-zA-Z_!~\'\(\)\[\]\.;\?:@&=\+\$,%#-\/^\*\|]*)?)$/';
  2566. if(!empty($url) && !preg_match($patern,$url))
  2567. {
  2568. return false;
  2569. }
  2570. else
  2571. return true;
  2572. }
  2573. /*
  2574. * 转成元
  2575. * $money 金额
  2576. */
  2577. function transform_yuan($money){
  2578. $money =intval($money);
  2579. if($money){
  2580. return $money * 10000;
  2581. }
  2582. }
  2583. /*
  2584. * 元转成逆转万元
  2585. * $money 金额
  2586. */
  2587. function transform_wan($money){
  2588. $money =intval($money);
  2589. if($money){
  2590. return $money/10000;
  2591. }
  2592. }
  2593. function create_app_js($app_conf){
  2594. $node_app=APP_ROOT_PATH."public/node_app.js";
  2595. if(is_file($node_app)){
  2596. $content=file_get_contents($node_app);
  2597. $url = get_domain().APP_ROOT;
  2598. $content=str_replace("{domain}",$url,$content);
  2599. if($app_conf['IS_SMS_DIRECT']==0){
  2600. $deal_msg_list= 'true';
  2601. }else{
  2602. $deal_msg_list= 'false';
  2603. }
  2604. $content=str_replace("{deal_msg_list}",$deal_msg_list,$content);
  2605. $time = $app_conf['SEND_SPAN']?$app_conf['SEND_SPAN']*1000:500;
  2606. $content=str_replace("{time}",$time,$content);
  2607. $app=APP_ROOT_PATH."public/app.js";
  2608. file_put_contents($app,$content);
  2609. }
  2610. }
  2611. /* 微信提现
  2612. * */
  2613. function wx_withdraw_cash($refund_id){
  2614. $msg_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user_refund where id = ".$refund_id." and is_pay =1 ");
  2615. $order_id = $msg_item['id'];
  2616. $user_info = $GLOBALS['db']->getRow("select gz_openid,nick_name from ".DB_PREFIX."user where id=".$msg_item['user_id']);
  2617. $open_id = $user_info['gz_openid'];
  2618. //过滤中文支付 防止微信发送红包失败 //@、#、【】、
  2619. $user_name = strFilter($user_info['nick_name']);
  2620. $ticket = $msg_item['ticket'];
  2621. if($msg_item)
  2622. {
  2623. $payment_info = $GLOBALS['db']->getRow("select id,config,logo from ".DB_PREFIX."payment where class_name='Wwxjspay'");
  2624. $payment_info['config'] = unserialize($payment_info['config']);
  2625. $wx_config=$payment_info['config'];
  2626. $mch_appid=$wx_config['appid'];
  2627. $mchid=$wx_config['mchid'];//商户号
  2628. $nonce_str='qyzf'.rand(100000, 999999);//随机数
  2629. $partner_trade_no='wx'.$order_id.time().rand(10000, 99999);;//商户订单号
  2630. $openid=$open_id;//用户唯一标识
  2631. $check_name='NO_CHECK';//校验用户姓名选项,NO_CHECK:不校验真实姓名 FORCE_CHECK:强校验真实姓名(未实名认证的用户会校验失败,无法转账)OPTION_CHECK:针对已实名认证的用户才校验真实姓名(未实名认证用户不校验,可以转账成功)
  2632. $re_user_name=$user_name;//用户姓名
  2633. $m_config = load_auto_cache("m_config");//初始化手机端配置
  2634. //$amount=intval(floatval($ticket*$m_config['exchange_rate'])*100);//金额(以分为单位,必须大于100)
  2635. $amount = floatval($msg_item['money']*100);
  2636. $desc='红包';//描述
  2637. require_once APP_ROOT_PATH.'system/extend/ip.php';
  2638. $iplocation = new iplocate();
  2639. $spbill_create_ip = $iplocation->getIP();
  2640. //封装成数据
  2641. $dataArr=array();
  2642. $dataArr['amount']=$amount;
  2643. $dataArr['check_name']=$check_name;
  2644. $dataArr['desc']=$desc;
  2645. $dataArr['mch_appid']=$mch_appid;
  2646. $dataArr['mchid']=$mchid;
  2647. $dataArr['nonce_str']=$nonce_str;
  2648. $dataArr['openid']=$openid;
  2649. $dataArr['partner_trade_no']=$partner_trade_no;
  2650. $dataArr['re_user_name']=$re_user_name;
  2651. $dataArr['spbill_create_ip']=$spbill_create_ip;
  2652. $sign=getSign($dataArr,$wx_config['key']);
  2653. $data="<xml>
  2654. <mch_appid>".$mch_appid."</mch_appid>
  2655. <mchid>".$mchid."</mchid>
  2656. <nonce_str>".$nonce_str."</nonce_str>
  2657. <partner_trade_no>".$partner_trade_no."</partner_trade_no>
  2658. <openid>".$openid."</openid>
  2659. <check_name>".$check_name."</check_name>
  2660. <re_user_name>".$re_user_name."</re_user_name>
  2661. <amount>".$amount."</amount>
  2662. <desc>".$desc."</desc>
  2663. <spbill_create_ip>".$spbill_create_ip."</spbill_create_ip>
  2664. <sign>".$sign."</sign>
  2665. </xml>";
  2666. $ch = curl_init ();
  2667. $MENU_URL="https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";
  2668. curl_setopt ( $ch, CURLOPT_URL, $MENU_URL );
  2669. curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
  2670. curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
  2671. curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
  2672. // $zs1=APP_ROOT_PATH."public/weixin/apiclient_cert.pem";
  2673. // $zs2=APP_ROOT_PATH."public/weixin/apiclient_key.pem";
  2674. $zs1=APP_ROOT_PATH.$wx_config['sslcert'];
  2675. $zs2=APP_ROOT_PATH.$wx_config['sslkey'];
  2676. curl_setopt($ch,CURLOPT_SSLCERT,$zs1);
  2677. curl_setopt($ch,CURLOPT_SSLKEY,$zs2);
  2678. // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01;
  2679. // Windows NT 5.0)');
  2680. curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
  2681. curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
  2682. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
  2683. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  2684. $info = curl_exec ( $ch );
  2685. if (curl_errno ( $ch )) {
  2686. log_result_wx('Errno' . curl_error ( $ch ));
  2687. }
  2688. curl_close ( $ch );
  2689. $return = (array)simplexml_load_string($info, 'SimpleXMLElement', LIBXML_NOCDATA);
  2690. if($return['return_code']=='SUCCESS'&&$return['result_code']=='SUCCESS'){
  2691. $refund_data = array();
  2692. $refund_data = M("UserRefund")->getById($refund_id);
  2693. $refund_data['pay_log'] ='已付款';
  2694. $refund_data['is_pay'] =3;
  2695. $refund_data['partner_trade_no'] =$partner_trade_no;
  2696. $refund_data['ybdrawflowid'] =$return['payment_no'];
  2697. $refund_data['pay_time'] =NOW_TIME;
  2698. $refund_data['confirm_cash_ip'] = get_client_ip();
  2699. M("UserRefund")->save($refund_data);
  2700. $res_up_m = M("UserRefund")->save($refund_data);
  2701. if(!$res_up_m){
  2702. $sql = "update ".DB_PREFIX."user_refund set pay_log='已付款',is_pay = 3,partner_trade_no = '".$partner_trade_no."',ybdrawflowid='".$return['payment_no']."',pay_time = ".NOW_TIME.",confirm_cash_ip = '".get_client_ip()."' where id = ".$order_id;
  2703. $res = $GLOBALS['db']->query($sql);
  2704. }
  2705. $payment_data = array();
  2706. $payment_data = M("Payment")->getById($payment_info['id']);
  2707. $payment_data['total_amount'] =$payment_data['total_amount']+$msg_item['money'];
  2708. $res_p_m = M("Payment")->save($payment_data);
  2709. if(!$res_p_m){
  2710. $sql = "update ".DB_PREFIX."payment set total_amount = total_amount + ".$msg_item['money']." where id = ".$payment_info['id'];
  2711. $res = $GLOBALS['db']->query($sql);
  2712. }
  2713. return true;
  2714. }else{
  2715. $refund_data = array();
  2716. $refund_data = M("UserRefund")->getById($order_id);
  2717. $refund_data['pay_log'] =$return['return_msg'].$return['err_code_des'];
  2718. $refund_data['partner_trade_no'] =$partner_trade_no;
  2719. $refund_data['is_pay'] = 4;
  2720. $refund_data['confirm_cash_ip'] = get_client_ip();
  2721. $res_up_m = M("UserRefund")->save($refund_data);
  2722. if(!$res_up_m){
  2723. $GLOBALS['db']->query("update ".DB_PREFIX."user_refund set confirm_cash_ip = '".get_client_ip()."' is_pay=4,pay_log = '".$return['return_msg']."',partner_trade_no = '".$partner_trade_no."' where id = ".$order_id);
  2724. }
  2725. return false;
  2726. }
  2727. }
  2728. }
  2729. /**
  2730. * 作用:生成签名
  2731. */
  2732. function getSign($Obj,$key)
  2733. {
  2734. //var_dump($Obj);//die;
  2735. foreach ($Obj as $k => $v)
  2736. {
  2737. $Parameters[$k] = $v;
  2738. }
  2739. //签名步骤一:按字典序排序参数
  2740. ksort($Parameters);
  2741. $String = formatBizQueryParaMap($Parameters, false);
  2742. //echo '【string1】'.$String.'</br>';
  2743. //签名步骤二:在string后加入KEY
  2744. $String = $String."&key=".$key;
  2745. //echo "【string2】".$String."</br>";
  2746. //签名步骤三:MD5加密
  2747. $String = md5($String);
  2748. //echo "【string3】 ".$String."</br>";
  2749. //签名步骤四:所有字符转为大写
  2750. $result_ = strtoupper($String);
  2751. //echo "【result】 ".$result_."</br>";
  2752. return $result_;
  2753. }
  2754. /**
  2755. * 作用:格式化参数,签名过程需要使用
  2756. */
  2757. function formatBizQueryParaMap($paraMap, $urlencode)
  2758. {
  2759. $buff = "";
  2760. ksort($paraMap);
  2761. foreach ($paraMap as $k => $v)
  2762. {
  2763. if($urlencode)
  2764. {
  2765. $v = urlencode($v);
  2766. }
  2767. //$buff .= strtolower($k) . "=" . $v . "&";
  2768. $buff .= $k . "=" . $v . "&";
  2769. }
  2770. //$reqPar;
  2771. if (strlen($buff) > 0)
  2772. {
  2773. $reqPar = substr($buff, 0, strlen($buff)-1);
  2774. }
  2775. return $reqPar;
  2776. }
  2777. /**
  2778. * 获得查询次数以及查询时间
  2779. *
  2780. * @access public
  2781. * @return string
  2782. */
  2783. function run_info()
  2784. {
  2785. if(!SHOW_DEBUG)return "";
  2786. $query_time = number_format($GLOBALS['db']->queryTime,6);
  2787. if($GLOBALS['begin_run_time']==''||$GLOBALS['begin_run_time']==0)
  2788. {
  2789. $run_time = 0;
  2790. }
  2791. else
  2792. {
  2793. if (PHP_VERSION >= '5.0.0')
  2794. {
  2795. $run_time = number_format(microtime(true) - $GLOBALS['begin_run_time'], 6);
  2796. }
  2797. else
  2798. {
  2799. list($now_usec, $now_sec) = explode(' ', microtime());
  2800. list($start_usec, $start_sec) = explode(' ', $GLOBALS['begin_run_time']);
  2801. $run_time = number_format(($now_sec - $start_sec) + ($now_usec - $start_usec), 6);
  2802. }
  2803. }
  2804. /* 内存占用情况 */
  2805. if (function_exists('memory_get_usage'))
  2806. {
  2807. $unit=array('B','KB','MB','GB');
  2808. $size = memory_get_usage();
  2809. $used = @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
  2810. $memory_usage = "占用内存 ".$used;
  2811. }
  2812. else
  2813. {
  2814. $memory_usage = '';
  2815. }
  2816. /* 是否启用了 gzip */
  2817. $enabled_gzip = (app_conf("GZIP_ON") && function_exists('ob_gzhandler'));
  2818. $gzip_enabled = $enabled_gzip ? "gzip开启" : "gzip关闭";
  2819. $str = '共执行 '.$GLOBALS['db']->queryCount.' 个查询,用时 '.$query_time.' 秒,'.$gzip_enabled.','.$memory_usage.',程序执行时间 '.$run_time.' 秒';
  2820. foreach($GLOBALS['db']->queryLog as $K=>$sql)
  2821. {
  2822. if($K==0)$str.="<br />SQL语句列表:";
  2823. $str.="<br />行".($K+1).":".$sql;
  2824. }
  2825. return "<div style='width:940px; padding:10px; line-height:22px; border:1px solid #ccc; text-align:left; margin:30px auto; font-size:14px; color:#999; height:150px; overflow-y:auto;'>".$str."</div>";
  2826. }
  2827. function update_sys_config()
  2828. {
  2829. $filename = APP_ROOT_PATH."public/sys_config.php";
  2830. if(!file_exists($filename))
  2831. {
  2832. //定义DB
  2833. require APP_ROOT_PATH.'system/db/db.php';
  2834. $dbcfg = require APP_ROOT_PATH."public/db_config.php";
  2835. define('DB_PREFIX', $dbcfg['DB_PREFIX']);
  2836. if(!file_exists(APP_ROOT_PATH.'public/runtime/app/db_caches/'))
  2837. mkdir(APP_ROOT_PATH.'public/runtime/app/db_caches/',0777);
  2838. $pconnect = false;
  2839. $db = new mysql_db($dbcfg['DB_HOST'].":".$dbcfg['DB_PORT'], $dbcfg['DB_USER'],$dbcfg['DB_PWD'],$dbcfg['DB_NAME'],'utf8',$pconnect);
  2840. //end 定义DB
  2841. $sys_configs = $db->getAll("select * from ".DB_PREFIX."conf");
  2842. $config_str = "<?php\n";
  2843. $config_str .= "return array(\n";
  2844. foreach($sys_configs as $k=>$v)
  2845. {
  2846. $config_str.="'".$v['name']."'=>'".addslashes($v['value'])."',\n";
  2847. }
  2848. $config_str.=");\n ?>";
  2849. file_put_contents($filename,$config_str);
  2850. $url = APP_ROOT."/";
  2851. app_redirect($url);
  2852. }
  2853. }
  2854. function get_admin_nav($role_id,$adm_name){
  2855. if(CHANGE_NAV=='default'||!defined('CHANGE_NAV')){
  2856. if($adm_name == app_conf('DEFAULT_ADMIN')){
  2857. if(defined("MODULE_ADMIN")&&MODULE_ADMIN==1){
  2858. $navs = require_once APP_ROOT_PATH."system/admnav_cfg_pc.php";
  2859. }else{
  2860. $navs = require_once APP_ROOT_PATH."system/admnav_cfg.php";
  2861. }
  2862. }else{
  2863. $navs = load_auto_cache("admin_nav",array('id'=>$role_id));
  2864. }
  2865. if($_REQUEST['change_nav']){
  2866. $navs = require_once APP_ROOT_PATH."system/admnav_cfg_".$_REQUEST['change_nav'].".php";
  2867. }
  2868. }else{
  2869. $navs = require_once APP_ROOT_PATH."system/admnav_cfg_".CHANGE_NAV.".php";
  2870. }
  2871. return deal_admin_nav($navs);
  2872. }
  2873. function deal_admin_nav($navs){
  2874. if(!defined("OPEN_FAMILY_MODULE")||OPEN_FAMILY_MODULE==0){
  2875. unset($navs['user']['groups']['family']);
  2876. unset($navs['payment']['groups']['cash']['nodes'][2]);
  2877. }
  2878. $m_config = load_auto_cache("m_config");//初始化手机端配置 ljz
  2879. if(!defined("OPEN_SOCIETY_MODULE")||OPEN_SOCIETY_MODULE==0||$m_config['society_pattern']==0){//添加公会模式开关
  2880. unset($navs['user']['groups']['society']);
  2881. //unset($navs['user']['groups']['society']['nodes'][1]);
  2882. //unset($navs['payment']['groups']['cash']['nodes'][1]);
  2883. }else{
  2884. unset($navs['user']['groups']['family']);
  2885. unset($navs['payment']['groups']['cash']['nodes'][2]);
  2886. }
  2887. if($m_config['society_pattern']!=2){//非无抽成模式下关闭公会收益列表、公会提现列表
  2888. unset($navs['user']['groups']['society']['nodes'][1]);
  2889. unset($navs['payment']['groups']['cash']['nodes'][1]);
  2890. }
  2891. if(!defined("OPEN_LUCK_NUM")||OPEN_LUCK_NUM==0){
  2892. unset($navs['system']['groups']['lucknum']);
  2893. }
  2894. if(!defined("OPEN_ADS")||OPEN_ADS==0){
  2895. unset($navs['system']['groups']['ads']);
  2896. }
  2897. if(intval(OPEN_SLBGROUP)==0){
  2898. unset($navs['system']['groups']['slbgroupconf']);
  2899. }
  2900. if (!defined("OPEN_GAME_MODULE")||OPEN_GAME_MODULE==0) {
  2901. unset($navs['PlugIn']['groups']['gameconf']);
  2902. } else {
  2903. if (!defined("OPEN_BANKER_MODULE")||OPEN_BANKER_MODULE==0) {
  2904. foreach ($navs['PlugIn']['groups']['gameconf']['nodes'] as $key => $value) {
  2905. if ($value['action']=='bankerLog') {
  2906. unset($navs['PlugIn']['groups']['gameconf']['nodes'][$key]);
  2907. }
  2908. }
  2909. }
  2910. if (defined('OPEN_DIAMOND_GAME_MODULE') && OPEN_DIAMOND_GAME_MODULE == 1) {
  2911. foreach ($navs['PlugIn']['groups']['gameconf']['nodes'] as $key => $value) {
  2912. $navs['PlugIn']['groups']['gameconf']['nodes'][$key]['name'] = str_replace('金币', '钻石', $value['name']);
  2913. }
  2914. }
  2915. }
  2916. if (!defined("SHOPPING_GOODS")||SHOPPING_GOODS==0) {
  2917. unset($navs['PlugIn']['groups']['goodsconf']);
  2918. unset($navs['PlugIn']['groups']['user_goodsconf']);
  2919. }
  2920. if((!defined("OPEN_PAI_MODULE")||OPEN_PAI_MODULE==0) && (!defined("SHOPPING_GOODS")||SHOPPING_GOODS==0)){
  2921. unset($navs['PlugIn']['groups']['goods_complaint']);
  2922. }
  2923. if (!defined("OPEN_PAI_MODULE")||OPEN_PAI_MODULE==0) {
  2924. unset($navs['PlugIn']['groups']['pai_goods']);
  2925. unset($navs['PlugIn']['groups']['goods_order']);
  2926. }
  2927. if(!defined("OPEN_PODCAST_GOODS")||OPEN_PODCAST_GOODS==0){
  2928. foreach ($navs['PlugIn']['groups']['user_goodsconf']['nodes'] as $key => $value) {
  2929. if ($value['module']=='PodcastGoods') {
  2930. unset($navs['PlugIn']['groups']['user_goodsconf']['nodes'][$key]);
  2931. }
  2932. }
  2933. }
  2934. if(!defined("PAI_VIRTUAL_BTN")||PAI_VIRTUAL_BTN==0){
  2935. foreach ($navs['PlugIn']['groups']['goods_order']['nodes'] as $key => $value) {
  2936. if ($value['module']=='PaiTags') {
  2937. unset($navs['PlugIn']['groups']['goods_order']['nodes'][$key]);
  2938. }
  2939. }
  2940. }
  2941. if (!defined("OPEN_EDU_MODULE")||OPEN_EDU_MODULE==0) {
  2942. unset($navs['edu_courses']);
  2943. }
  2944. $m_config = load_auto_cache("m_config");//初始化手机端配置
  2945. if($m_config['name_limit']==0){
  2946. unset($navs['system']['groups']['mobile']['nodes'][2]);
  2947. }
  2948. if($m_config['has_dirty_words']==0){
  2949. unset($navs['system']['groups']['mobile']['nodes'][1]);
  2950. }
  2951. if(!defined("OPEN_VIP")||OPEN_VIP==0){
  2952. unset($navs['system']['groups']['sysconf']['nodes'][4]);
  2953. }
  2954. if(!defined("OPEN_DISTRIBUTION")||OPEN_DISTRIBUTION==0){
  2955. unset($navs['user']['groups']['distribution']);
  2956. }
  2957. if(!defined("CHECK_VIDEO")||CHECK_VIDEO==0){
  2958. unset($navs['dealcate']['groups']['video']['nodes'][5]);
  2959. }
  2960. //微信分销
  2961. if (!defined('WEIXIN_DISTRIBUTION') || WEIXIN_DISTRIBUTION==0) {
  2962. unset($navs['user']['groups']['wx_distribution']);
  2963. }
  2964. //推广分销
  2965. if (!defined('GAME_DISTRIBUTION_TOP') || GAME_DISTRIBUTION_TOP==0) {
  2966. unset($navs['user']['groups']['tg_distribution']);
  2967. }
  2968. //子房间
  2969. if(!defined('CHILD_ROOM') || CHILD_ROOM == 0){
  2970. unset($navs['dealcate']['groups']['childroom']);
  2971. }
  2972. //西藏青稞
  2973. if(!defined('QK_TREE') || QK_TREE == 0){
  2974. unset($navs['qk_tree']['groups']['qk_tree']);
  2975. }
  2976. return $navs;
  2977. }
  2978. /*
  2979. * @return 删除过期的验证码
  2980. */
  2981. function delete_mobile_verify_code(){
  2982. $time=app_conf("USER_SEND_VERIFY_TIME")?app_conf("USER_SEND_VERIFY_TIME"):300;
  2983. $n_time=get_gmtime()-$time;
  2984. //删除超过时间的验证码
  2985. $GLOBALS['db']->query("DELETE FROM ".DB_PREFIX."mobile_verify_code WHERE create_time <=".$n_time);
  2986. }
  2987. function theme_parse_css($urls)
  2988. {
  2989. $url = md5(implode(',',$urls));
  2990. $css_url = 'public/runtime/statics/'.$url.'.css';
  2991. $url_path = APP_ROOT_PATH.$css_url;
  2992. if(!file_exists($url_path))
  2993. {
  2994. if(!file_exists(APP_ROOT_PATH.'public/runtime/statics/'))
  2995. mkdir(APP_ROOT_PATH.'public/runtime/statics/',0777);
  2996. $tmpl_path = get_domain().APP_ROOT."/theme";
  2997. $css_content = '';
  2998. foreach($urls as $url)
  2999. {
  3000. $css_content .= @file_get_contents($url);
  3001. }
  3002. $css_content = preg_replace("/[\r\n]/",'',$css_content);
  3003. $css_content = str_replace("../../images",$tmpl_path."/images/",$css_content);
  3004. $css_content = str_replace("../images/",$tmpl_path."/images/",$css_content);
  3005. // @file_put_contents($url_path, unicode_encode($css_content));
  3006. @file_put_contents($url_path, $css_content);
  3007. }
  3008. return get_domain().APP_ROOT."/".$css_url."?v=1.0";
  3009. }
  3010. //添加图片前缀
  3011. function add_domain_url($image){
  3012. if(strpos($image, 'http://')===false){
  3013. $image = str_replace('images/',file_domain().'/theme/images/',$image);
  3014. $image = str_replace('./public/',file_domain().'/public/',$image);
  3015. }
  3016. return $image;
  3017. }
  3018. //删除图片前缀
  3019. function del_domain_url($image){
  3020. if(strchr($image,'http://')!==false){
  3021. $image = str_replace(file_domain().'/public/','/public/',$image);
  3022. /*$index = strpos($image,'/public');
  3023. $image = '.'.substr($image,$index);*/
  3024. }
  3025. return $image;
  3026. }
  3027. //检查会员等级
  3028. /*function chack_grade($user_id){
  3029. //$user_info= $GLOBALS['db']->getRow("select u.score,u.online_time,u.user_level from ".DB_PREFIX."user as u where u.id=".$user_id);
  3030. //redis 读取
  3031. require_once(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3032. require_once(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3033. $user_redis = new UserRedisService();
  3034. $user_info = $user_redis->getRow_db($user_id,array('score','online_time','user_level'));
  3035. $up_score = $user_info['score']+floor($user_info['online_time']/app_conf('ONLINETIME_TO_EXPERIENCE'));
  3036. $level_info = $GLOBALS['db']->getRow("select ul.name as level_name,ul.level as level,ul.icon as icon from ".DB_PREFIX."user_level as ul where ul.score<=".$up_score." ORDER BY ul.id DESC limit 0,1");
  3037. if(intval($user_id)>0&&$user_info['user_level']<$level_info['level']){
  3038. $status =$GLOBALS['db']->query("update ".DB_PREFIX."user set user_level=".$level_info['level']." where id=".$user_id);
  3039. //redis 更新
  3040. $user['user_level'] = $level_info['level'];
  3041. $status = $user_redis->update_db($user_id,$user);
  3042. }
  3043. }*/
  3044. function agentArr(){
  3045. $agent = $_SERVER['HTTP_USER_AGENT'];
  3046. $agent_array = array();
  3047. if($agent){
  3048. $agent_arr = explode(" ",$agent);
  3049. foreach($agent_arr as $k=>$v){
  3050. $kkv = explode("/",$v);
  3051. $agent_array[$kkv[0]] = strim($kkv[1]);
  3052. }
  3053. }
  3054. return $agent_array;
  3055. }
  3056. /**
  3057. * 散列算法
  3058. * @param unknown_type $value 计算散列的基础值
  3059. * @param unknown_type $count 散列的总基数
  3060. * @return number
  3061. */
  3062. function hash_table($value,$count)
  3063. {
  3064. $pid = intval(round(hexdec(md5($value))/pow(10,32))%$count);
  3065. return $pid;
  3066. }
  3067. function file_domain(){
  3068. if($GLOBALS['distribution_cfg']['CSS_JS_OSS']&&$GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  3069. {
  3070. $domain = $GLOBALS['distribution_cfg']['OSS_FILE_DOMAIN'];
  3071. }
  3072. else
  3073. {
  3074. $domain = get_domain().APP_ROOT;
  3075. }
  3076. return $domain;
  3077. }
  3078. //发登录超时短信
  3079. function send_tips_sms($mobile,$overtime)
  3080. {
  3081. return $GLOBALS['msg']->sms_tips($mobile,$overtime);
  3082. }
  3083. //获取一个新的用户号,同时记录分配给那个系统使用
  3084. function get_max_user_id($sysid=0){
  3085. $user_id = get_max_user_id_fun($sysid);
  3086. if (OPEN_LUCK_NUM == 1){//如果开启了新版靓号功能
  3087. if(check_luck_num($user_id)){
  3088. //重新生成
  3089. $user_id = get_max_user_id($sysid);
  3090. }
  3091. }else {//没开启靓号,继续使用最初版幸运号逻辑
  3092. if (chack_lucky_num($user_id)) {
  3093. $data=array();
  3094. $data['id'] = $user_id ;
  3095. $data['nick_name']= "系统保留吉祥号";
  3096. $data['is_effect'] = 1;
  3097. $data['sex']= 1;
  3098. $data['create_time']= NOW_TIME;
  3099. $data['user_pwd']= md5(rand(100000,999999));
  3100. $data['login_ip'] = CLIENT_IP;
  3101. $data['login_time'] = to_date(NOW_TIME);
  3102. $data['synchronize'] = 0;
  3103. $data['emotional_state'] ='保密';
  3104. if($data['city']==''&&$data['province']==''){
  3105. $data['province'] = '火星';
  3106. }
  3107. $data['job'] = '主播';
  3108. $data['user_level'] = 1;
  3109. $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data);
  3110. $user_info = $data;
  3111. // ===========add start ===========
  3112. fanwe_require (APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3113. $user_redis = new UserRedisService();
  3114. $ridis_data = $user_redis->reg_data($data);
  3115. $user_redis->insert_db($user_id,$ridis_data);
  3116. $user_info = $data;
  3117. // 登录成功 同步信息
  3118. accountimport($user_info);
  3119. }
  3120. }
  3121. return $user_id;
  3122. }
  3123. //获取一个新的用户号,同时记录分配给那个系统使用
  3124. function get_max_user_id_fun($sysid=0){
  3125. $sql = "insert into ".DB_PREFIX."user_id (id,sysid) values(0,$sysid)";
  3126. $GLOBALS['db']->query($sql);
  3127. $user_id = $GLOBALS['db']->insert_id();
  3128. return $user_id;
  3129. }
  3130. //判断 吉祥号
  3131. function chack_lucky_num($user_id=0){
  3132. $m_config = load_auto_cache("m_config");
  3133. $lucky_num = explode(",",$m_config['lucky_num']);
  3134. return in_array($user_id, $lucky_num);
  3135. }
  3136. //判断id是否是靓号
  3137. function check_luck_num($user_id=0){
  3138. $sql = "SELECT * FROM ".DB_PREFIX."luck_num where luck_num = ".$user_id;
  3139. $result = array();
  3140. $result = $GLOBALS['db']->getRow($sql,true,true);
  3141. return $result;
  3142. }
  3143. function log_file($word,$file_name='log_file')
  3144. {
  3145. if(!IS_DEBUG){
  3146. return false;
  3147. }
  3148. $file = APP_ROOT_PATH."/public/".$file_name.".log";
  3149. if (is_array($word)) $word = var_export($word,true);
  3150. $fp = fopen($file,"a");
  3151. flock($fp, LOCK_EX) ;
  3152. fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
  3153. flock($fp, LOCK_UN);
  3154. fclose($fp);
  3155. }
  3156. function get_abs_img_root($content)
  3157. {
  3158. return str_replace("./public/",file_domain()."/public/",$content);
  3159. //return str_replace('/mapi/','/',$str);
  3160. }
  3161. /**
  3162. *更新会员等
  3163. *$user_data 要包括会员id,会员等级,会员信用值
  3164. * */
  3165. function user_leverl_syn($user_data)
  3166. {
  3167. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3168. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3169. //$user_redis = new UserRedisService($user_data['id']);
  3170. $user_redis = new UserRedisService();
  3171. $m_config = load_auto_cache("m_config");
  3172. //合并等级 判断,用户当前等级积分
  3173. $ote = floatval($m_config['onlinetime_to_experience']);
  3174. if ($ote > 0){
  3175. $user_score = $user_data['score']+floor($user_data['online_time']*$ote);
  3176. }else{
  3177. $user_score = $user_data['score'];
  3178. }
  3179. //$user_score = $user_data['score']+floor($user_data['online_time']/app_conf('ONLINETIME_TO_EXPERIENCE'));
  3180. //$user_score = $user_data['score'];
  3181. //用户获取当前等级
  3182. //旧的,获取等级
  3183. // $user_current_level = $GLOBALS['db']->getRow("select point from ".DB_PREFIX."user_level where `level` = ".intval($user_data['user_level']),true,true);
  3184. //$user_current_level = load_auto_cache("user_level_lv",array('lv'=>intval($user_data['user_level'])));
  3185. //新的,通过redis获取等级
  3186. $user_level_info = load_auto_cache("user_level");
  3187. $user_level = null;
  3188. foreach($user_level_info as $v){
  3189. // 两层关系即可
  3190. unset($user_level['next_level']);
  3191. $v['next_level'] = $user_level;
  3192. $user_level = $v;
  3193. if($v['point']<=intval($user_score)){
  3194. break;
  3195. }
  3196. }
  3197. //旧的,获取最高等级积分信息
  3198. //$user_level = $GLOBALS['db']->getRow("select point,level from ".DB_PREFIX."user_level where point <=".intval($user_score)." order by point desc",true,true);
  3199. if(intval($user_data['user_level'])<$user_level['level'])
  3200. {
  3201. //$user_data['user_level'] = intval($user_level['level']);
  3202. $GLOBALS['db']->query("update ".DB_PREFIX."user set user_level = ".$user_level['level']." where id = ".$user_data['id']);
  3203. $data = array();
  3204. $data['user_level'] = $user_level['level'];
  3205. $user_redis->update_db($user_data['id'],$data);
  3206. //$pm_content = "恭喜您,您已经成为".$user_level['name']."等级的会员!";
  3207. //send_notify($user_data['id'], $pm_content, "account#point");
  3208. }
  3209. /*
  3210. if($user_current_level['point']>$user_level['point'])
  3211. {
  3212. $user_data['user_level'] = intval($user_level['level']);
  3213. $GLOBALS['db']->query("update ".DB_PREFIX."user set user_level = ".$user_data['user_level']." where id = ".$user_data['id']);
  3214. $data = array();
  3215. $data['user_level'] = $user_data['user_level'];
  3216. $user_redis->update_db($user_data['id'],$user_data);
  3217. //$pm_content = "很报歉,您的会员等级已经降为".$user_level['name']."!";
  3218. //send_notify($user_data['id'], $pm_content, "account#point");
  3219. }
  3220. */
  3221. $user_level['u_score'] = $user_score;
  3222. return $user_level;
  3223. }
  3224. /**
  3225. *更新会员等
  3226. *$user_data 要包括会员id,会员等级,会员信用值
  3227. * */
  3228. function family_level_syn($family_info)
  3229. {
  3230. $family_score = $family_info['score'];
  3231. $family_level_info = load_auto_cache("family_level");
  3232. $family_level = null;
  3233. foreach($family_level_info as $v) {
  3234. // 两层关系即可
  3235. unset($family_level['next_level']);
  3236. $v['next_level'] = $family_level;
  3237. $family_level = $v;
  3238. if ($v['point'] <= intval($family_score)) {
  3239. break;
  3240. }
  3241. }
  3242. if($family_level && intval($family_info['family_level']) < $family_level['level'])
  3243. {
  3244. $GLOBALS['db']->query("update ".DB_PREFIX."family set family_level = ".$family_level['level']." where id = ".$family_info['family_id']);
  3245. // $data = array();
  3246. // $data['family_level'] = $family_level['level'];
  3247. // $$family_redis->update_db($family_info['id'],$data);
  3248. }
  3249. return $family_level;
  3250. }
  3251. function fanwe_require($file){
  3252. static $_importFile = array();
  3253. $filename = realpath($file);
  3254. if(!isset($_importFile[$filename])){
  3255. //做兼容性,只有强制定义了 FANWE_REQUIRE 常量后,才使用 后台用require,否则使用:require_once
  3256. if(defined('FANWE_REQUIRE')){
  3257. $_importFile[$filename] = require $file;
  3258. }else{
  3259. $_importFile[$filename] = require_once $file;
  3260. }
  3261. }
  3262. return $_importFile[$filename];
  3263. }
  3264. function FanweServiceCall($class='index',$act='index',$data=array())
  3265. {
  3266. if(file_exists(APP_ROOT_PATH."service/config.php")){
  3267. $config = fanwe_require(APP_ROOT_PATH."service/config.php");
  3268. }
  3269. if(!isset($config[$class])){
  3270. $config[$class] = "fanwe";
  3271. }
  3272. @fanwe_require(APP_ROOT_PATH."service/".$config[$class]."/".$class.".service.php");
  3273. $objClass = $class."Service";
  3274. if(class_exists($objClass)){
  3275. $obj=new $objClass;
  3276. if(method_exists($obj, $act)){
  3277. return $obj->$act($data);
  3278. }
  3279. else{
  3280. $error["status"] = 10006;
  3281. $error["error"] = "接口方法不存在";
  3282. ajax_return($error);
  3283. }
  3284. }
  3285. else{
  3286. $error["status"] = 10005;
  3287. $error["error"] = "接口不存在";
  3288. ajax_return($error);
  3289. }
  3290. }
  3291. /**
  3292. * 获取毫秒
  3293. */
  3294. function get_microtime(){
  3295. list($usec, $sec) = explode(" ", microtime());
  3296. $microtime = ((int)($usec * 1000) + (float)$sec * 1000);
  3297. return $microtime;
  3298. }
  3299. /*
  3300. * 获取不在 $array_2数组中的值
  3301. */
  3302. function array_diff_info($array_2,$array_1 ) {
  3303. $array_2 = array_flip($array_2);
  3304. foreach ($array_1 as $key => $item) {
  3305. if (isset($array_2[$item])) {
  3306. unset($array_1[$key]);
  3307. }
  3308. }
  3309. return $array_1;
  3310. }
  3311. /**
  3312. * TimApi推送
  3313. * 'MsgType' => 'TIMCustomElem',
  3314. */
  3315. function get_tim_api($data){
  3316. #构造高级接口所需参数
  3317. $msg_content = array();
  3318. //创建array 所需元素
  3319. $msg_content_elem = array(
  3320. 'MsgType' => 'TIMCustomElem', //自定义类型
  3321. 'MsgContent' => array(
  3322. 'Data' => json_encode($data['ext']),
  3323. 'Desc' => '',
  3324. )
  3325. );
  3326. //将创建的元素$msg_content_elem, 加入array $msg_content
  3327. array_push($msg_content, $msg_content_elem);
  3328. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  3329. $api = createTimAPI();
  3330. return $api->group_send_group_msg2(trim($data['podcast_id']), $data['group_id'], $msg_content);
  3331. }
  3332. function timSystemNotify($group_id,$msg,$to = array()){
  3333. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  3334. $msg['timestamp'] = microtime(1);
  3335. $msg['user_id'] = sizeof($to) == 1 ? intval($to[0]) : 0;
  3336. $api = createTimAPI();
  3337. return $api->group_send_group_system_notification2($group_id,json_encode($msg),$to);
  3338. }
  3339. function isApp(){
  3340. $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  3341. $is_app = strpos($agent, 'fanwe_app_sdk') ? true : false ;
  3342. if($is_app){
  3343. return true;
  3344. }else{
  3345. return false;
  3346. }
  3347. }
  3348. /**
  3349. * 将 diamonds,use_diamonds,score,ticket,user_level,refund_ticket 几个字段值,同步到redis
  3350. * @param array $user_ids
  3351. */
  3352. function user_deal_to_reids($user_ids)
  3353. {
  3354. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3355. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3356. $user_redis = new UserRedisService();
  3357. $m_config = load_auto_cache("m_config");//初始化手机端配置
  3358. /*$fields = 'id,nick_name,head_image,sex,diamonds,use_diamonds,score,ticket,user_level,refund_ticket,is_authentication,v_icon,v_explain,v_type,emotional_state,province,city,job,signature,birthday,video_count';
  3359. if(defined('OPEN_VIP')&&OPEN_VIP==1){
  3360. $fields.=',is_vip,vip_expire_time';
  3361. }
  3362. if((defined('OPEN_GAME_MODULE')&&OPEN_GAME_MODULE==1)){
  3363. $fields.=',coin';
  3364. }*/
  3365. $fields = ' * ';
  3366. foreach ($user_ids as $user_id) {
  3367. $sql = "select ".$fields." from ".DB_PREFIX."user where id = ".$user_id;
  3368. //echo $sql."<br>";
  3369. $user_data = $GLOBALS['db']->getRow($sql);
  3370. //print_r($user_data);
  3371. $user_redis->update_db($user_id, $user_data);
  3372. }
  3373. }
  3374. //将机器人同步到IM
  3375. function accountimport_robots($user_id){
  3376. fanwe_require(APP_ROOT_PATH."system/libs/user.php");
  3377. $user_data = $GLOBALS['db']->getRow("SELECT id,nick_name,head_image,synchronize FROM ".DB_PREFIX."user where id=".$user_id." and is_robot=1 ");
  3378. accountimport($user_data);
  3379. }
  3380. function account_log_com($data,$user_id,$log_msg='',$param=array())
  3381. {
  3382. fanwe_require(APP_ROOT_PATH."system/libs/user.php");
  3383. account_log($data,$user_id,$log_msg,$param);
  3384. }
  3385. function origin_image_info($img_path)
  3386. {
  3387. if (!isset($GLOBALS['distribution_cfg']['OSS_TYPE']) || $GLOBALS['distribution_cfg']['OSS_TYPE'] != "ALI_OSS") {
  3388. return array('file_name' => $img_path);
  3389. }
  3390. $i = strrpos($img_path, '@');
  3391. if ($i === false) {
  3392. return array('file_name' => $img_path);
  3393. }
  3394. $result = array('file_name' => substr($img_path, 0, $i));
  3395. foreach (explode('_', substr($img_path, $i + 1, strrpos($img_path, '.') - $i - 1)) as $str) {
  3396. $key = substr($str, -1);
  3397. if (strpos($str, '-') === false) {
  3398. $result[$key] = substr($str, 0, -1);
  3399. } else {
  3400. $result[$key] = explode('-', substr($str, 0, -1));
  3401. }
  3402. }
  3403. return $result;
  3404. }
  3405. /*
  3406. * 获取裁剪规格的图片地址(https://help.aliyun.com/document_detail/32228.html?spm=5176.doc32228.6.558.59iwnS)
  3407. * @param string $img_path 图片地址,只支持阿里云oss图片地址
  3408. * @param int $x ===》x轴起始坐标
  3409. * @param int $y===》y轴起始坐标
  3410. * @param int $width ===》高
  3411. * @param int $height===》宽
  3412. * @param int $rotate ===》旋转角度
  3413. * @return String 返回格式化后的图片地址
  3414. *
  3415. *图片旋转, https://help.aliyun.com/document_detail/32230.html?spm=5176.doc32228.6.560.R1A6Ki
  3416. */
  3417. function get_cut_image($img_path,$x=0, $y=0, $width=0,$height=0,$rotate=0)
  3418. {
  3419. if (!isset($GLOBALS['distribution_cfg']['OSS_TYPE']) || $GLOBALS['distribution_cfg']['OSS_TYPE'] != "ALI_OSS") {
  3420. return $img_path;
  3421. }
  3422. $pos = strpos($img_path, $GLOBALS['distribution_cfg']['OSS_DOMAIN']);
  3423. $httppos = strpos($img_path, 'http');
  3424. $pathinfo = pathinfo($img_path);
  3425. if ($pos === false && $httppos === false) {
  3426. //未定位到
  3427. $file = $pathinfo['basename'];
  3428. $dir = $pathinfo['dirname'];
  3429. $dir = str_replace("./public/", "/public/", $dir);
  3430. $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file;
  3431. $pos = 0;
  3432. } else {
  3433. $file_name = $img_path;
  3434. }
  3435. if ($pos === 0) {
  3436. if($rotate < 0){
  3437. $rotate = 360 + $rotate;
  3438. }
  3439. if ($GLOBALS['distribution_cfg']['NEW_OSS']) {
  3440. $file_name .= "?x-oss-process=image/crop,x_{$x},y_{$y},w_{$width},h_{$height}/rotate,{$rotate}";
  3441. } else {
  3442. $format = "@{$x}-{$y}-{$width}-{$height}a_{$rotate}r.";
  3443. if (isset($pathinfo['extension'])) {
  3444. $extension = strtolower($pathinfo['extension']);
  3445. } else {
  3446. $extension = "jpg";
  3447. }
  3448. $file_name .= $format . $extension;
  3449. }
  3450. }
  3451. return $file_name;
  3452. }
  3453. /*
  3454. * 获取相应规格的图片地址(https://help.aliyun.com/document_detail/32206.html?spm=5176.doc32206.6.488.Y4uU6M)
  3455. * @param string $img_path 图片地址,只支持阿里云oss图片地址
  3456. * @param int $width ===》高
  3457. * @param int $height===》宽
  3458. * @param int $gen gen=0:保持比例缩放,不剪裁,如高为0,则保证宽度按比例缩放 gen=1:保证长宽,剪裁
  3459. *
  3460. * @param int $radius ===》模糊效果,取值在 [1,50], radius越大,越模糊
  3461. * @param int $sigma===》模糊效果 ,取值 [1,50],越大,越模糊
  3462. * @return String 返回格式化后的图片地址
  3463. *
  3464. *模糊效果, https://help.aliyun.com/document_detail/32234.html?spm=5176.doc32233.6.516.zuzpF7
  3465. */
  3466. function get_spec_image($img_path,$width=0,$height=0,$gen=0, $radius=0,$sigma=0)
  3467. {
  3468. if($img_path==''){
  3469. return ;
  3470. }
  3471. //关于ALIOSS的生成
  3472. if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] == "ALI_OSS") {
  3473. $pos = strpos($img_path, $GLOBALS['distribution_cfg']['OSS_DOMAIN']);
  3474. $httppos = strpos($img_path, 'http');
  3475. if ($pos === false && $httppos === false) {
  3476. //未定位到
  3477. $pathinfo = pathinfo($img_path);
  3478. $file = $pathinfo['basename'];
  3479. $dir = $pathinfo['dirname'];
  3480. $dir = str_replace("./public/", "/public/", $dir);
  3481. $allow_extension = array('mp4','flv','m3u8');
  3482. $extension = pathinfo($file, PATHINFO_EXTENSION);
  3483. $is_allow = in_array($extension,$allow_extension);
  3484. if($width!=0||$height!=0||$gen!=0||$radius!=0||$sigma!=0||$GLOBALS['distribution_cfg']['OSS_DOMAIN_HTTPS']==''||$is_allow){
  3485. $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . $dir . "/" . $file;
  3486. }else{
  3487. $file_name = $GLOBALS['distribution_cfg']['OSS_DOMAIN_HTTPS'] . $dir . "/" . $file;
  3488. return $file_name;
  3489. }
  3490. $pos = 0;
  3491. } else {
  3492. $file_name = $img_path;
  3493. }
  3494. if ($GLOBALS['distribution_cfg']['NEW_OSS']) {
  3495. if ($pos === 0) {
  3496. $format = "";
  3497. if ($width == 0 && $height > 0) {
  3498. $format = "/resize,h_".$height; //高固定,宽按图片大小等比缩放
  3499. } else if ($height == 0 && $width > 0) {
  3500. $format = "/resize,w_".$width;//宽固定,高按图片大小等比缩放
  3501. } else if ($width > 0 && $height > 0) {
  3502. if ($gen == 0)
  3503. $format = "/resize,m_mfit,h_" . $height . ",w_". $width;//宽,高固定,以短边缩放 1e 不剪裁
  3504. else
  3505. $format = "/resize,m_fill,m_mfit,h_" . $height . ",w_". $width;//宽,高固定,以短边缩放 1e 剪裁
  3506. }
  3507. if ($radius > 0 && $sigma > 0) {
  3508. if ($format == '')
  3509. $format = "/blur,r_" . $radius . ",s_" . $sigma;
  3510. else
  3511. $format = $format."/blur,r_" . $radius . ",s_" . $sigma;
  3512. }
  3513. if ($format != '') {
  3514. $i = strrpos($file_name, '?x-oss-process=image');
  3515. if ($i === false) {
  3516. $file_name = $file_name . '?x-oss-process=image' . $format;
  3517. } else {
  3518. $file_name .= $format;
  3519. }
  3520. }
  3521. }
  3522. }else{
  3523. if ($pos === 0) {
  3524. $format = "";
  3525. if ($width == 0 && $height > 0) {
  3526. $format = $height . "h_1l_1x"; //高固定,宽按图片大小等比缩放
  3527. } else if ($height == 0 && $width > 0) {
  3528. $format = $width . "w_1l_1x";//宽固定,高按图片大小等比缩放
  3529. } else if ($width > 0 && $height > 0) {
  3530. if ($gen == 0)
  3531. $format = $width . "w_" . $height . "h_0c_1e_1x"; //宽,高固定,以短边缩放 1e 不剪裁
  3532. else
  3533. $format = $width . "w_" . $height . "h_1c_1e_1x"; //宽,高固定,以短边缩放 1e 剪裁
  3534. }
  3535. if ($radius > 0 && $sigma > 0) {
  3536. if ($format == '')
  3537. $format = $radius . "-" . $sigma . "bl";
  3538. else
  3539. $format = "_" . $radius . "-" . $sigma . "bl";
  3540. }
  3541. if ($format != '') {
  3542. $i = strrpos($file_name, '@');
  3543. if ($i === false) {
  3544. $file_name = $file_name . '@' . $format . ".jpg";
  3545. } else {
  3546. $i = strrpos($file_name, '.');
  3547. $file_name = substr($file_name, 0, $i) . '_' . $format . substr($file_name, $i);
  3548. }
  3549. }
  3550. }
  3551. }
  3552. return $file_name;
  3553. } else {
  3554. $domain = get_domain();
  3555. if($GLOBALS['distribution_cfg']['LOCAL_IMAGE_URL'] != "") {
  3556. $domain = $GLOBALS['distribution_cfg']['LOCAL_IMAGE_URL'];
  3557. }
  3558. $img_path = str_replace("./public/",$domain.APP_ROOT."/public/",$img_path);
  3559. return $img_path;
  3560. }
  3561. }
  3562. //登录提示
  3563. function login_prompt($user_id){
  3564. $root = array('first_login'=>0,'new_level'=>0);
  3565. $m_config = load_auto_cache("m_config");//初始化手机端配置
  3566. $login_send_score = intval($m_config['login_send_score']);//每日首次登录赠送积分数
  3567. $upgrade_level = intval($m_config['upgrade_level']);//首次登录升级提示等级
  3568. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3569. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3570. $user_redis = new UserRedisService($user_id);
  3571. //每日首次登录赠送积分
  3572. if(defined("OPEN_LOGIN_SEND_SCORE")&&OPEN_LOGIN_SEND_SCORE == 1){
  3573. if($login_send_score>0){
  3574. $now_time = NOW_TIME;
  3575. /*$now_time = to_date($now_time,"Y-m-d 00:00:00");
  3576. $timezone = intval(app_conf('TIME_ZONE')) * 3600;
  3577. $user_log_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user_log where user_id = ".intval($user_id)." and type = 5 and FROM_UNIXTIME(log_time+".$timezone.",'%Y-%m-%d')='".to_date(NOW_TIME,'Y-m-d')."'");
  3578. */
  3579. $s_now_time = to_timespan(to_date($now_time,"Y-m-d 00:00:00"));
  3580. $e_now_time = to_timespan(to_date($now_time,"Y-m-d 23:59:59"));
  3581. $user_log_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user_log where " .
  3582. "user_id = ".intval($user_id)." and type = 5 and log_time>".$s_now_time." and log_time<".$e_now_time);
  3583. if(intval($user_log_id)==0){
  3584. $user = $user_redis->getRow_db($user_id,array("login_time"));
  3585. if($user['login_time']<$now_time){
  3586. $GLOBALS['db']->query("update ".DB_PREFIX."user set score = score+".$login_send_score." where id =".$user_id);
  3587. user_deal_to_reids(array($user_id));
  3588. $user = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
  3589. user_leverl_syn($user);
  3590. $root['first_login'] = 1;
  3591. //写入用户日志
  3592. $data = array();
  3593. $data['score'] = $login_send_score;
  3594. $data['log_admin_id'] = 0;
  3595. $param['type'] = 5;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 分享获得印票 5 登录赠送积分
  3596. $log_msg ='每日首次登录获得'.$login_send_score.'积分';
  3597. account_log_com($data,$user_id,$log_msg,$param);
  3598. }
  3599. }
  3600. }
  3601. }
  3602. //每次登录等级提示
  3603. if(defined("OPEN_UPGRADE_PROMPT")&&OPEN_UPGRADE_PROMPT == 1){
  3604. if($upgrade_level){
  3605. $user = $user_redis->getRow_db($user_id,array("user_level","last_login_level"));
  3606. if($user['user_level']>=$upgrade_level && $user["last_login_level"]<$user['user_level']){//等级大于等于升级提示并且上一次登录时的等级小于现在的等级
  3607. $root['new_level'] = $user['user_level'];
  3608. //修改上一次登录时的等级
  3609. $GLOBALS['db']->query("update ".DB_PREFIX."user set last_login_level = ".$user['user_level']." where id =".$user_id);
  3610. $user_redis->update_db($user_id,array("last_login_level"=>$user['user_level']));
  3611. }
  3612. }
  3613. }
  3614. return $root;
  3615. }
  3616. //管理员结束直播
  3617. function admin_do_end_video($video,$video_vid,$is_aborted = 0,$cate_id = 0){
  3618. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/common.php');
  3619. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3620. //请求同步redis数据到mysql,防止结束时候mysql数据未同步导致的当前处理的数据错误;
  3621. $sql = "SELECT id FROM " . DB_PREFIX . "video";
  3622. $list = $GLOBALS['db']->getAll($sql, true, true);
  3623. if (count($list) > 0) {
  3624. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  3625. $video_redis_syn = new VideoRedisService();
  3626. foreach ($list as $k => $v) {
  3627. $video_id_syn = $v['id'];
  3628. //计算权重
  3629. $video_redis_syn ->syn_sort_num($video_id_syn);
  3630. $fields = array('share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number');
  3631. $video_syn = $video_redis_syn->getRow_db($video_id_syn, $fields);
  3632. $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $video_syn, "UPDATE", "id=" . $video_id_syn);
  3633. }
  3634. }
  3635. $result = do_end_video($video,$video_vid,$is_aborted,$cate_id);
  3636. return $result;
  3637. }
  3638. //获取后台地址
  3639. function get_manage_url_name(){
  3640. $url_name = "m.php";
  3641. $urlname = app_conf("URL_NAME");
  3642. if($urlname!=$url_name&&$urlname!=''){
  3643. $url_name = $urlname;
  3644. }
  3645. return $url_name;
  3646. }
  3647. function strFilter($str){
  3648. $str = str_replace('`', '', $str);
  3649. $str = str_replace('·', '', $str);
  3650. $str = str_replace('~', '', $str);
  3651. $str = str_replace('!', '', $str);
  3652. $str = str_replace('!', '', $str);
  3653. $str = str_replace('@', '', $str);
  3654. $str = str_replace('#', '', $str);
  3655. $str = str_replace('$', '', $str);
  3656. $str = str_replace('¥', '', $str);
  3657. $str = str_replace('%', '', $str);
  3658. $str = str_replace('^', '', $str);
  3659. $str = str_replace('……', '', $str);
  3660. $str = str_replace('&', '', $str);
  3661. $str = str_replace('*', '', $str);
  3662. $str = str_replace('(', '', $str);
  3663. $str = str_replace(')', '', $str);
  3664. $str = str_replace('(', '', $str);
  3665. $str = str_replace(')', '', $str);
  3666. $str = str_replace('-', '', $str);
  3667. $str = str_replace('_', '', $str);
  3668. $str = str_replace('——', '', $str);
  3669. $str = str_replace('+', '', $str);
  3670. $str = str_replace('=', '', $str);
  3671. $str = str_replace('|', '', $str);
  3672. $str = str_replace('\\', '', $str);
  3673. $str = str_replace('[', '', $str);
  3674. $str = str_replace(']', '', $str);
  3675. $str = str_replace('【', '', $str);
  3676. $str = str_replace('】', '', $str);
  3677. $str = str_replace('{', '', $str);
  3678. $str = str_replace('}', '', $str);
  3679. $str = str_replace(';', '', $str);
  3680. $str = str_replace(';', '', $str);
  3681. $str = str_replace(':', '', $str);
  3682. $str = str_replace(':', '', $str);
  3683. $str = str_replace('\'', '', $str);
  3684. $str = str_replace('"', '', $str);
  3685. $str = str_replace('“', '', $str);
  3686. $str = str_replace('”', '', $str);
  3687. $str = str_replace(',', '', $str);
  3688. $str = str_replace(',', '', $str);
  3689. $str = str_replace('<', '', $str);
  3690. $str = str_replace('>', '', $str);
  3691. $str = str_replace('《', '', $str);
  3692. $str = str_replace('》', '', $str);
  3693. $str = str_replace('.', '', $str);
  3694. $str = str_replace('。', '', $str);
  3695. $str = str_replace('/', '', $str);
  3696. $str = str_replace('、', '', $str);
  3697. $str = str_replace('?', '', $str);
  3698. $str = str_replace('?', '', $str);
  3699. return trim($str);
  3700. }
  3701. //系统错误日志
  3702. function log_err_file($word,$file_name='error_file')
  3703. {
  3704. //log_err_file(array(__FILE__,__LINE__,__METHOD__,$data));
  3705. if (!is_dir(APP_ROOT_PATH."public/sys_error/")) {
  3706. @mkdir(APP_ROOT_PATH."public/sys_error/");
  3707. @chmod(APP_ROOT_PATH."public/sys_error/", 0777);
  3708. }
  3709. $file = APP_ROOT_PATH."/public/sys_error/".$file_name."_".date('Ymd').".log";
  3710. if (is_array($word)) $word = var_export($word,true);
  3711. $fp = fopen($file,"a");
  3712. flock($fp, LOCK_EX) ;
  3713. fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n".$word."\n\n");
  3714. flock($fp, LOCK_UN);
  3715. fclose($fp);
  3716. //删除大于一个月的日志文件
  3717. $file_time = getlastMonthDays();//获取上个月时间
  3718. $file_name_old = $file_name."_".$file_time;
  3719. $file_old = APP_ROOT_PATH."public/sys_error/".$file_name_old.".log";
  3720. if (file_exists($file_old)) {
  3721. @unlink ($file_old);
  3722. }
  3723. }
  3724. //获取直播信息
  3725. function c_get_vodset_by_video_id($video_id){
  3726. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/common.php');
  3727. $result = get_vodset_by_video_id($video_id);
  3728. return $result;
  3729. }
  3730. /*
  3731. * $url 文件地址
  3732. * $qrcode_name 生成的源文件
  3733. * $qrcode_dir_logo 带logo的源文件
  3734. */
  3735. function get_qrcode_png($url,$qrcode_name,$qrcode_dir_logo){
  3736. require_once APP_ROOT_PATH.'system/utils/phpqrcode.php';
  3737. $value = $url; //二维码内容
  3738. $errorCorrectionLevel = 'L';//容错级别
  3739. $matrixPointSize = 6;//生成图片大小
  3740. //生成二维码图片
  3741. QRcode::png($value, $qrcode_name, $errorCorrectionLevel, $matrixPointSize, 2);
  3742. $m_config = load_auto_cache("m_config");//初始化手机端配置
  3743. $logo = $m_config['app_logo'];//准备好的logo图片
  3744. $QR = $qrcode_name;//已经生成的原始二维码图
  3745. if ($logo !== FALSE) {
  3746. $QR = imagecreatefromstring(file_get_contents($QR));
  3747. $logo = imagecreatefromstring(file_get_contents($logo));
  3748. $QR_width = imagesx($QR);//二维码图片宽度
  3749. $QR_height = imagesy($QR);//二维码图片高度
  3750. $logo_width = imagesx($logo);//logo图片宽度
  3751. $logo_height = imagesy($logo);//logo图片高度
  3752. $logo_qr_width = $QR_width / 5;
  3753. $scale = $logo_width/$logo_qr_width;
  3754. $logo_qr_height = $logo_height/$scale;
  3755. $from_width = ($QR_width - $logo_qr_width) / 2;
  3756. //重新组合图片并调整大小
  3757. imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
  3758. $logo_qr_height, $logo_width, $logo_height);
  3759. }
  3760. //输出图片
  3761. imagepng($QR, $qrcode_dir_logo);
  3762. }
  3763. /*
  3764. * 数据传输加密
  3765. * @param array $date 输出的数组
  3766. * @param int $r_type 0=>base64;1=>json_encode;2=>array; 4=>aec
  3767. */
  3768. function ajax_return_aes($data,$r_type=1,$is_debug=0){
  3769. header("Content-Type:text/html; charset=utf-8");
  3770. filter_null($data);//过滤null
  3771. //过滤false
  3772. $data = filter_all_false($data);
  3773. $encrypt = $GLOBALS['encrypt'];
  3774. //if(strstr($encrypt['sdk_version_name'],'2.4')||floatval($encrypt['sdk_version_name'])>=2.5||floatval($encrypt['sdk_version_name'])==0){
  3775. $aes_key_list = get_privatekey();
  3776. if(is_array($aes_key_list[0]['aes_key'])){
  3777. $privatekey = $aes_key_list[0]['aes_key'][0];
  3778. }else{
  3779. $privatekey = $aes_key_list[0]['aes_key'];
  3780. }
  3781. $is_aes_extra = get_aes_extra();
  3782. if($encrypt['now_aes_key']!=''&&$is_aes_extra){
  3783. $privatekey = $encrypt['now_aes_key'];
  3784. }
  3785. /*}else{
  3786. $m_config = load_auto_cache("m_config");//初始化手机端配置
  3787. $privatekey = $m_config['tim_sdkappid'];//对称加密KEY
  3788. if(trim($privatekey)==''){
  3789. $ret = array('error'=>'tim_sdkappid为空');
  3790. log_err_file(array(__FILE__,__LINE__,__METHOD__,$ret));
  3791. }
  3792. //判断KEY是否16位,如果不是自动填充0,进行16位截取
  3793. //$privatekey = str_pad($privatekey,16,"0",STR_PAD_RIGHT);
  3794. if(strlen(trim($privatekey))<16){
  3795. $privatekey = trim($privatekey).'0000000000000000';
  3796. }
  3797. }*/
  3798. $privatekey = substr($privatekey,0,16);
  3799. $r_type = intval($r_type);//返回数据格式类型;
  3800. ob_start();
  3801. ob_end_clean();
  3802. if ($r_type == 0)
  3803. {
  3804. echo base64_encode(json_encode($data));
  3805. }else if ($r_type == 1)
  3806. {
  3807. echo json_encode($data);
  3808. }else if ($r_type == 2)
  3809. {
  3810. print_r($data);
  3811. }else if($r_type == 4){
  3812. require_once APP_ROOT_PATH.'system/libs/crypt_aes.php';
  3813. $aes = new CryptAES();
  3814. $aes->set_key($privatekey);
  3815. $aes->require_pkcs5();
  3816. $encText = array();
  3817. $encText['output'] = $aes->encrypt(json_encode($data));
  3818. if(intval(DE_BUGE)){
  3819. $encText['output_debug']['sdk_version_name'] = $encrypt['sdk_version_name'];
  3820. $encText['output_debug']['privatekey'] = $privatekey;
  3821. $encText['output_debug']['data'] = $data;
  3822. $encText['output_debug']['request'] = $_REQUEST;
  3823. }
  3824. echo json_encode($encText);
  3825. };
  3826. exit;
  3827. }
  3828. /*
  3829. * 接收的数据解密
  3830. * @param array $_REQUEST['requestData'] 接收的数据集
  3831. */
  3832. function aes_request_decode(){
  3833. $encrypt = $GLOBALS['encrypt'];
  3834. if($encrypt['i_type']){
  3835. $request = get_aes_decstring();
  3836. $_REQUEST = array_merge($_REQUEST,$request);
  3837. }
  3838. }
  3839. //获得时间时长
  3840. function time_len($time){
  3841. $total_time_format = '';
  3842. if($time/3600>=1){
  3843. $total_time_format.=intval($time/3600).'小时';
  3844. $time = $time%3600;
  3845. }
  3846. if($time/60>=1){
  3847. $total_time_format.=intval($time/60).'分钟';
  3848. $time = $time%60;
  3849. }
  3850. if($time){
  3851. $total_time_format.=intval($time).'秒';
  3852. }
  3853. return $total_time_format;
  3854. }
  3855. //登录日志
  3856. function log_login($date)
  3857. {
  3858. $login_log = array();
  3859. $now_time = get_gmtime();
  3860. $login_log['create_time'] = $now_time;
  3861. $login_log['ip'] = get_client_ip();
  3862. $login_log['login_date'] = to_date($now_time);
  3863. $login_log['login_time'] = $now_time;
  3864. $login_log['user_id'] = $date['user_id'];
  3865. $login_log['login_type'] = $date['login_type'];
  3866. $login_log['request'] = $date['request'];
  3867. $login_log['ctl_act'] =$GLOBALS['encrypt']['ctl'].'#'.$GLOBALS['encrypt']['act'];
  3868. $GLOBALS['db']->autoExecute(DB_PREFIX."login_log", $login_log,'INSERT');
  3869. }
  3870. //处理解密
  3871. function get_aes_decstring(){
  3872. require_once APP_ROOT_PATH.'system/libs/crypt_aes.php';
  3873. //获取aes_key
  3874. $is_aes_extra = get_aes_extra();
  3875. $aes_key_list = get_privatekey();
  3876. //获取aes_key
  3877. if($aes_key_list) {
  3878. if(count($aes_key_list)>1){
  3879. foreach($aes_key_list as $k=>$v){
  3880. $privatekey = $v['aes_key'];
  3881. if(count($privatekey)>1){
  3882. foreach($privatekey as $v){
  3883. $request = get_aes_request($v);
  3884. if($request!=''){
  3885. $privatekey = $v;
  3886. break;
  3887. }
  3888. }
  3889. }else{
  3890. $request = get_aes_request($privatekey[0]);
  3891. }
  3892. if($request&&$is_aes_extra){
  3893. $privatekey = $privatekey[0];
  3894. $GLOBALS['encrypt']['now_aes_key'] = $privatekey;
  3895. break;
  3896. }else{
  3897. $GLOBALS['encrypt']['now_aes_key'] = '';
  3898. }
  3899. }
  3900. }else{
  3901. $privatekey = $aes_key_list[0]['aes_key'];
  3902. if(count($privatekey)>1){
  3903. foreach($privatekey as $v){
  3904. $request = get_aes_request($v);
  3905. if($request!=''){
  3906. $privatekey = $v;
  3907. break;
  3908. }
  3909. }
  3910. }else{
  3911. if($privatekey) {
  3912. $privatekey = $privatekey[0];
  3913. $request = get_aes_request($privatekey);
  3914. }
  3915. }
  3916. if($request&&$is_aes_extra){
  3917. $GLOBALS['encrypt']['now_aes_key'] = $privatekey;
  3918. }else{
  3919. $GLOBALS['encrypt']['now_aes_key'] = '';
  3920. }
  3921. }
  3922. }else{
  3923. $m_config = load_auto_cache("m_config");//初始化手机端配置
  3924. $privatekey = $m_config['tim_sdkappid'];//对称加密KEY
  3925. $request = get_aes_request($privatekey);
  3926. if($request!=''&&$is_aes_extra){
  3927. $GLOBALS['encrypt']['now_aes_key'] = $privatekey;
  3928. }else{
  3929. $GLOBALS['encrypt']['now_aes_key'] = '';
  3930. }
  3931. }
  3932. return $request;
  3933. }
  3934. //获取动态秘钥
  3935. function get_privatekey(){
  3936. $is_aes_extra = get_aes_extra();
  3937. if(intval($is_aes_extra)){
  3938. $sql = "SELECT * from ".DB_PREFIX."key_list where is_effect=1 and is_delete=0 order by id desc ";
  3939. }else{
  3940. $sql = "SELECT * from ".DB_PREFIX."key_list where is_effect=1 and is_delete=0 order by id desc limit 1 ";
  3941. }
  3942. $aes_key_list = $GLOBALS['db']->getAll($sql);
  3943. if($aes_key_list){
  3944. foreach($aes_key_list as $k=>$v){
  3945. $aes_key_arr = explode("<br />",nl2br($v['aes_key']));
  3946. if($aes_key_arr){
  3947. foreach($aes_key_arr as &$item){
  3948. $item = trim($item);
  3949. }
  3950. $aes_key_list[$k]['aes_key']=$aes_key_arr;
  3951. }
  3952. }
  3953. }else{
  3954. $aes_key_list = array();
  3955. }
  3956. if($GLOBALS['encrypt']['now_aes_key']){
  3957. $aes_key_list[0]['aes_key'] = $GLOBALS['encrypt']['now_aes_key'];
  3958. }
  3959. return $aes_key_list;
  3960. }
  3961. //解密
  3962. function get_aes_request($privatekey){
  3963. //判断KEY是否16位,如果不是自动填充0,进行16位截取
  3964. $privatekey = trim($privatekey);
  3965. if(trim($privatekey)==''){
  3966. $ret = array('error'=>'tim_sdkappid为空');
  3967. log_err_file(array(__FILE__,__LINE__,__METHOD__,$ret));
  3968. }
  3969. if(strlen(trim($privatekey))<16){
  3970. $privatekey = trim($privatekey).'0000000000000000';
  3971. }
  3972. $privatekey = substr($privatekey,0,16);
  3973. $aes = new CryptAES();
  3974. $aes->set_key($privatekey);
  3975. $aes->require_pkcs5();
  3976. $decString = $aes->decrypt(trim($_REQUEST['requestData']));
  3977. $request = json_decode($decString, 1);
  3978. return $request;
  3979. }
  3980. //判断是否要循环解密
  3981. function get_aes_extra(){
  3982. $encrypt = $GLOBALS['encrypt'];
  3983. $is_aes_extra = 0;
  3984. $ctl_act = $encrypt['ctl']."#".$encrypt['act'];
  3985. if(count($GLOBALS['distribution_cfg']['AES_EXTRA_FUN'])>0&&in_array($ctl_act,$GLOBALS['distribution_cfg']['AES_EXTRA_FUN'])){
  3986. $is_aes_extra = 1;//需要循环解密
  3987. }
  3988. return $is_aes_extra;
  3989. }
  3990. //对emoji表情转义
  3991. function emoji_encode($str){
  3992. $strEncode = '';
  3993. $length = mb_strlen($str,'utf-8');
  3994. for ($i=0; $i < $length; $i++) {
  3995. $_tmpStr = mb_substr($str,$i,1,'utf-8');
  3996. if(strlen($_tmpStr) >= 4){
  3997. $strEncode .= '[[EMOJI:'.rawurlencode($_tmpStr).']]';
  3998. }else{
  3999. $strEncode .= $_tmpStr;
  4000. }
  4001. }
  4002. return $strEncode;
  4003. }
  4004. //对emoji表情转反义
  4005. function emoji_decode($str){
  4006. $strDecode = preg_replace_callback('|\[\[EMOJI:(.*?)\]\]|', function($matches){
  4007. return rawurldecode($matches[1]);
  4008. }, $str);
  4009. return $strDecode;
  4010. }
  4011. //日志输出
  4012. function log_ljz($word)
  4013. {
  4014. if (is_array($word)) $word = var_export($word,true);
  4015. $file = APP_ROOT_PATH."/public/log_ljz.log";
  4016. $fp = fopen($file,"a");
  4017. flock($fp, LOCK_EX) ;
  4018. $res = debug_backtrace();//回溯跟踪
  4019. fwrite($fp,"执行日期:".strftime("%Y-%m-%d-%H:%M:%S",time())."\n 文件所在位置:".$res[0]['file'].",位于第".$res[0]['line']."行\n".$word."\n\n");
  4020. flock($fp, LOCK_UN);
  4021. fclose($fp);
  4022. }
  4023. //获取上个月时间
  4024. function getlastMonthDays($date=0){
  4025. if(!$date){
  4026. $date = date('Ymd',time());
  4027. }else{
  4028. $date = date('Ymd',$date);
  4029. }
  4030. $lastday=date('Ymd',strtotime("$date -1 month "));
  4031. return $lastday;
  4032. }
  4033. //删除文件
  4034. function clear_file($path){
  4035. $result = false;
  4036. if(is_file($path)){
  4037. $result = @unlink($path);
  4038. if(!$result){
  4039. log_err_file(array(__FILE__,__LINE__,__METHOD__,'删除文件 '.$path.' 失败'),'clear_file_error');
  4040. }
  4041. }
  4042. return $result;
  4043. }
  4044. ?>