account.class.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class WeAccount extends ArrayObject {
  8. public $uniacid = 0;
  9. protected $account;
  10. protected $owner = array();
  11. protected $groups = array();
  12. protected $setting = array();
  13. protected $startTime;
  14. protected $endTime;
  15. protected $groupLevel;
  16. protected $logo;
  17. protected $qrcode;
  18. protected $switchUrl;
  19. protected $displayUrl;
  20. protected $setMeal = array();
  21. protected $sameAccountExist;
  22. protected $menuFrame;
  23. protected $type;
  24. protected $tablename;
  25. protected $typeName;
  26. protected $typeSign;
  27. protected $typeTemplate;
  28. protected $supportVersion = STATUS_OFF;
  29. protected $supportOauthInfo;
  30. protected $supportJssdk;
  31. protected $toArrayMap = array(
  32. 'type_sign' => 'typeSign',
  33. 'starttime' => 'startTime',
  34. 'endtime' => 'endTime',
  35. 'groups' => 'groups',
  36. 'setting' => 'setting',
  37. 'grouplevel' => 'groupLevel',
  38. 'logo' => 'logo',
  39. 'qrcode' => 'qrcode',
  40. 'type_name' => 'typeName',
  41. 'switchurl' => 'switchUrl',
  42. 'setmeal' => 'setMeal',
  43. 'current_user_role' => 'CurrentUserRole',
  44. );
  45. private static $accountClassname = array(
  46. ACCOUNT_TYPE_OFFCIAL_NORMAL => 'weixin.account',
  47. ACCOUNT_TYPE_OFFCIAL_AUTH => 'weixin.platform',
  48. ACCOUNT_TYPE_APP_NORMAL => 'wxapp.account',
  49. ACCOUNT_TYPE_APP_AUTH => 'wxapp.platform',
  50. ACCOUNT_TYPE_WXAPP_WORK => 'wxapp.work',
  51. ACCOUNT_TYPE_WEBAPP_NORMAL => 'webapp.account',
  52. ACCOUNT_TYPE_PHONEAPP_NORMAL => 'phoneapp.account',
  53. ACCOUNT_TYPE_XZAPP_NORMAL => 'xzapp.account',
  54. ACCOUNT_TYPE_XZAPP_AUTH => 'xzapp.platform',
  55. ACCOUNT_TYPE_ALIAPP_NORMAL => 'aliapp.account',
  56. ACCOUNT_TYPE_BAIDUAPP_NORMAL => 'baiduapp.account',
  57. ACCOUNT_TYPE_TOUTIAOAPP_NORMAL => 'toutiaoapp.account',
  58. );
  59. private static $accountObj = array();
  60. public function __construct($uniaccount = array()) {
  61. $this->uniacid = $uniaccount['uniacid'];
  62. $cachekey = cache_system_key('uniaccount', array('uniacid' => $this->uniacid));
  63. $cache = cache_load($cachekey);
  64. if (empty($cache)) {
  65. $cache = $this->getAccountInfo($uniaccount['acid']);
  66. cache_write($cachekey, $cache);
  67. }
  68. $this->account = array_merge((array)$cache, $uniaccount);
  69. }
  70. public function __get($name) {
  71. if (method_exists($this, $name)) {
  72. return $this->$name();
  73. }
  74. $funcname = 'fetch' . ucfirst($name);
  75. if (method_exists($this, $funcname)) {
  76. return $this->$funcname();
  77. }
  78. if (isset($this->$name)) {
  79. return $this->$name;
  80. }
  81. return false;
  82. }
  83. public static function create($acidOrAccount = array()) {
  84. global $_W;
  85. $uniaccount = array();
  86. if (is_object($acidOrAccount) && $acidOrAccount instanceof WeAccount) {
  87. return $acidOrAccount;
  88. }
  89. if (is_array($acidOrAccount) && !empty($acidOrAccount)) {
  90. $uniaccount = $acidOrAccount;
  91. } else {
  92. $acidOrAccount = empty($acidOrAccount) ? $_W['account']['acid'] : intval($acidOrAccount);
  93. $uniaccount = table('account')->getUniAccountByAcid($acidOrAccount);
  94. }
  95. if (is_error($uniaccount) || empty($uniaccount)) {
  96. $uniaccount = $_W['account'];
  97. }
  98. if (!empty(self::$accountObj[$uniaccount['uniacid']])) {
  99. return self::$accountObj[$uniaccount['uniacid']];
  100. }
  101. if(!empty($uniaccount) && isset($uniaccount['type']) || !empty($uniaccount['isdeleted'])) {
  102. return self::includes($uniaccount);
  103. } else {
  104. return error('-1', '帐号不存在或是已经被删除');
  105. }
  106. }
  107. public static function token($type = 1) {
  108. $obj = self::includes(array('type' => $type));
  109. return $obj->fetch_available_token();
  110. }
  111. public static function createByUniacid($uniacid = 0) {
  112. global $_W;
  113. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  114. if (!empty(self::$accountObj[$uniacid])) {
  115. return self::$accountObj[$uniacid];
  116. }
  117. $uniaccount = table('account')->getUniAccountByUniacid($uniacid);
  118. if (empty($uniaccount)) {
  119. return error('-1', '帐号不存在或是已经被删除');
  120. }
  121. if (!empty($_W['uid']) && !user_is_founder($_W['uid'], true) && !permission_account_user_role($_W['uid'], $uniacid)) {
  122. return error('-1', '无权限操作该平台账号');
  123. }
  124. return self::create($uniaccount);
  125. }
  126. public static function includes($uniaccount) {
  127. $type = $uniaccount['type'];
  128. if (empty(self::$accountClassname[$type])) {
  129. return error('-1', '账号类型不存在');
  130. }
  131. $file = self::$accountClassname[$type];
  132. $classname = self::getClassName($file);
  133. load()->classs($file);
  134. $account_obj = new $classname($uniaccount);
  135. self::$accountObj[$uniaccount['uniacid']] = $account_obj;
  136. return $account_obj;
  137. }
  138. public static function getClassName($filename) {
  139. $classname = '';
  140. $filename = explode('.', $filename);
  141. foreach ($filename as $val) {
  142. $classname .= ucfirst($val);
  143. }
  144. return $classname;
  145. }
  146. public function fetchAccountInfo() {
  147. return $this->getAccountInfo($this->account['acid']);
  148. }
  149. protected function fetchDisplayUrl() {
  150. return url('account/display', array('type' => $this->typeSign));
  151. }
  152. protected function fetchCurrentUserRole() {
  153. global $_W;
  154. load()->model('permission');
  155. return permission_account_user_role($_W['uid'], $this->uniacid);
  156. }
  157. protected function fetchLogo() {
  158. return to_global_media('headimg_'.$this->account['acid']. '.jpg').'?time='.time();
  159. }
  160. protected function fetchQrcode() {
  161. return to_global_media('qrcode_'.$this->account['acid']. '.jpg').'?time='.time();
  162. }
  163. protected function fetchSwitchUrl() {
  164. return wurl('account/display/switch', array('uniacid' => $this->uniacid));
  165. }
  166. protected function fetchOwner() {
  167. $this->owner = account_owner($this->uniacid);
  168. return $this->owner;
  169. }
  170. protected function fetchStartTime() {
  171. if (empty($this->owner)) {
  172. $this->owner = $this->fetchOwner();
  173. }
  174. return $this->owner['starttime'];
  175. }
  176. protected function fetchEndTime() {
  177. if (!empty($this->account['endtime'])) {
  178. return $this->account['endtime'] == '-1' ? 0 : $this->account['endtime'];
  179. } else {
  180. if (empty($this->owner)) {
  181. $this->owner = $this->fetchOwner();
  182. }
  183. return $this->owner['endtime'];
  184. }
  185. }
  186. protected function fetchGroups() {
  187. load()->model('mc');
  188. $this->groups = mc_groups($this->uniacid);
  189. return $this->groups;
  190. }
  191. protected function fetchSetting() {
  192. $this->setting = uni_setting($this->uniacid);
  193. return $this->setting;
  194. }
  195. protected function fetchGroupLevel() {
  196. if (empty($this->setting)) {
  197. $this->setting = $this->fetchSetting();
  198. }
  199. return $this->setting['grouplevel'];
  200. }
  201. protected function fetchSetMeal() {
  202. return uni_setmeal($this->uniacid);
  203. }
  204. protected function fetchSameAccountExist() {
  205. return pdo_getall($this->tablename, array('key' => $this->account['key'], 'uniacid <>' => $this->uniacid), array(), 'uniacid');
  206. }
  207. protected function supportOauthInfo() {
  208. if ($this->typeSign == ACCOUNT_TYPE_SIGN && $this->account['level'] == ACCOUNT_SERVICE_VERIFY || $this->typeSign == XZAPP_TYPE_SIGN) {
  209. return STATUS_ON;
  210. } else {
  211. return STATUS_OFF;
  212. }
  213. }
  214. protected function supportJssdk() {
  215. if (in_array($this->typeSign, array(XZAPP_TYPE_SIGN, WXAPP_TYPE_SIGN, ACCOUNT_TYPE_SIGN))) {
  216. return STATUS_ON;
  217. } else {
  218. return STATUS_OFF;
  219. }
  220. }
  221. public function __toArray() {
  222. foreach ($this->account as $key => $property) {
  223. $this[$key] = $property;
  224. }
  225. foreach($this->toArrayMap as $key => $type) {
  226. if (isset($this->$type) && !empty($this->$type)) {
  227. $this[$key] = $this->$type;
  228. } else {
  229. $this[$key] = $this->__get($type);
  230. }
  231. }
  232. return $this;
  233. }
  234. public function parse($message) {
  235. global $_W;
  236. if (!empty($message)){
  237. $message = xml2array($message);
  238. $packet = iarray_change_key_case($message, CASE_LOWER);
  239. $packet['from'] = $message['FromUserName'];
  240. $packet['to'] = $message['ToUserName'];
  241. $packet['time'] = $message['CreateTime'];
  242. $packet['type'] = $message['MsgType'];
  243. $packet['event'] = $message['Event'];
  244. switch ($packet['type']) {
  245. case 'text':
  246. $packet['redirection'] = false;
  247. $packet['source'] = null;
  248. break;
  249. case 'image':
  250. $packet['url'] = $message['PicUrl'];
  251. break;
  252. case 'video':
  253. case 'shortvideo':
  254. $packet['thumb'] = $message['ThumbMediaId'];
  255. break;
  256. }
  257. switch ($packet['event']) {
  258. case 'subscribe':
  259. $packet['type'] = 'subscribe';
  260. case 'SCAN':
  261. if ($packet['event'] == 'SCAN') {
  262. $packet['type'] = 'qr';
  263. }
  264. if(!empty($packet['eventkey'])) {
  265. $packet['scene'] = str_replace('qrscene_', '', $packet['eventkey']);
  266. if(strexists($packet['scene'], '\u')) {
  267. $packet['scene'] = '"' . str_replace('\\u', '\u', $packet['scene']) . '"';
  268. $packet['scene'] = json_decode($packet['scene']);
  269. }
  270. }
  271. break;
  272. case 'unsubscribe':
  273. $packet['type'] = 'unsubscribe';
  274. break;
  275. case 'LOCATION':
  276. $packet['type'] = 'trace';
  277. $packet['location_x'] = $message['Latitude'];
  278. $packet['location_y'] = $message['Longitude'];
  279. break;
  280. case 'pic_photo_or_album':
  281. case 'pic_weixin':
  282. case 'pic_sysphoto':
  283. $packet['sendpicsinfo']['piclist'] = array();
  284. $packet['sendpicsinfo']['count'] = $message['SendPicsInfo']['Count'];
  285. if (!empty($message['SendPicsInfo']['PicList'])) {
  286. foreach ($message['SendPicsInfo']['PicList']['item'] as $item) {
  287. if (empty($item)) {
  288. continue;
  289. }
  290. $packet['sendpicsinfo']['piclist'][] = is_array($item) ? $item['PicMd5Sum'] : $item;
  291. }
  292. }
  293. break;
  294. case 'card_pass_check':
  295. case 'card_not_pass_check':
  296. case 'user_get_card':
  297. case 'user_del_card':
  298. case 'user_consume_card':
  299. case 'poi_check_notify':
  300. $packet['type'] = 'coupon';
  301. break;
  302. }
  303. }
  304. return $packet;
  305. }
  306. public function response($packet) {
  307. if (is_error($packet)) {
  308. return '';
  309. }
  310. if (!is_array($packet)) {
  311. return $packet;
  312. }
  313. if(empty($packet['CreateTime'])) {
  314. $packet['CreateTime'] = TIMESTAMP;
  315. }
  316. if(empty($packet['MsgType'])) {
  317. $packet['MsgType'] = 'text';
  318. }
  319. if(empty($packet['FuncFlag'])) {
  320. $packet['FuncFlag'] = 0;
  321. } else {
  322. $packet['FuncFlag'] = 1;
  323. }
  324. return array2xml($packet);
  325. }
  326. public function errorCode($code, $errmsg = '未知错误') {
  327. $errors = array(
  328. '-1' => '系统繁忙',
  329. '0' => '请求成功',
  330. '40001' => '获取access_token时AppSecret错误,或者access_token无效',
  331. '40002' => '不合法的凭证类型',
  332. '40003' => '不合法的OpenID',
  333. '40004' => '不合法的媒体文件类型',
  334. '40005' => '不合法的文件类型',
  335. '40006' => '不合法的文件大小',
  336. '40007' => '不合法的媒体文件id',
  337. '40008' => '不合法的消息类型',
  338. '40009' => '不合法的图片文件大小',
  339. '40010' => '不合法的语音文件大小',
  340. '40011' => '不合法的视频文件大小',
  341. '40012' => '不合法的缩略图文件大小',
  342. '40013' => '不合法的APPID',
  343. '40014' => '不合法的access_token',
  344. '40015' => '不合法的菜单类型',
  345. '40016' => '不合法的按钮个数',
  346. '40017' => '不合法的按钮个数',
  347. '40018' => '不合法的按钮名字长度',
  348. '40019' => '不合法的按钮KEY长度',
  349. '40020' => '不合法的按钮URL长度',
  350. '40021' => '不合法的菜单版本号',
  351. '40022' => '不合法的子菜单级数',
  352. '40023' => '不合法的子菜单按钮个数',
  353. '40024' => '不合法的子菜单按钮类型',
  354. '40025' => '不合法的子菜单按钮名字长度',
  355. '40026' => '不合法的子菜单按钮KEY长度',
  356. '40027' => '不合法的子菜单按钮URL长度',
  357. '40028' => '不合法的自定义菜单使用用户',
  358. '40029' => '不合法的oauth_code',
  359. '40030' => '不合法的refresh_token',
  360. '40031' => '不合法的openid列表',
  361. '40032' => '不合法的openid列表长度',
  362. '40033' => '不合法的请求字符,不能包含\uxxxx格式的字符',
  363. '40035' => '不合法的参数',
  364. '40038' => '不合法的请求格式',
  365. '40039' => '不合法的URL长度',
  366. '40050' => '不合法的分组id',
  367. '40051' => '分组名字不合法',
  368. '40155' => '请勿添加其他公众号的主页链接',
  369. '41001' => '缺少access_token参数',
  370. '41002' => '缺少appid参数',
  371. '41003' => '缺少refresh_token参数',
  372. '41004' => '缺少secret参数',
  373. '41005' => '缺少多媒体文件数据',
  374. '41006' => '缺少media_id参数',
  375. '41007' => '缺少子菜单数据',
  376. '41008' => '缺少oauth code',
  377. '41009' => '缺少openid',
  378. '42001' => 'access_token超时',
  379. '42002' => 'refresh_token超时',
  380. '42003' => 'oauth_code超时',
  381. '43001' => '需要GET请求',
  382. '43002' => '需要POST请求',
  383. '43003' => '需要HTTPS请求',
  384. '43004' => '需要接收者关注',
  385. '43005' => '需要好友关系',
  386. '44001' => '多媒体文件为空',
  387. '44002' => 'POST的数据包为空',
  388. '44003' => '图文消息内容为空',
  389. '44004' => '文本消息内容为空',
  390. '45001' => '多媒体文件大小超过限制',
  391. '45002' => '消息内容超过限制',
  392. '45003' => '标题字段超过限制',
  393. '45004' => '描述字段超过限制',
  394. '45005' => '链接字段超过限制',
  395. '45006' => '图片链接字段超过限制',
  396. '45007' => '语音播放时间超过限制',
  397. '45008' => '图文消息超过限制',
  398. '45009' => '接口调用超过限制',
  399. '45010' => '创建菜单个数超过限制',
  400. '45015' => '回复时间超过限制',
  401. '45016' => '系统分组,不允许修改',
  402. '45017' => '分组名字过长',
  403. '45018' => '分组数量超过上限',
  404. '45056' => '创建的标签数过多,请注意不能超过100个',
  405. '45057' => '该标签下粉丝数超过10w,不允许直接删除',
  406. '45058' => '不能修改0/1/2这三个系统默认保留的标签',
  407. '45059' => '有粉丝身上的标签数已经超过限制',
  408. '45065' => '24小时内不可给该组人群发该素材',
  409. '45157' => '标签名非法,请注意不能和其他标签重名',
  410. '45158' => '标签名长度超过30个字节',
  411. '45159' => '非法的标签',
  412. '46001' => '不存在媒体数据',
  413. '46002' => '不存在的菜单版本',
  414. '46003' => '不存在的菜单数据',
  415. '46004' => '不存在的用户',
  416. '47001' => '解析JSON/XML内容错误',
  417. '48001' => 'api功能未授权',
  418. '48003' => '请在微信平台开启群发功能',
  419. '50001' => '用户未授权该api',
  420. '40070' => '基本信息baseinfo中填写的库存信息SKU不合法。',
  421. '41011' => '必填字段不完整或不合法,参考相应接口。',
  422. '40056' => '无效code,请确认code长度在20个字符以内,且处于非异常状态(转赠、删除)。',
  423. '43009' => '无自定义SN权限,请参考开发者必读中的流程开通权限。',
  424. '43010' => '无储值权限,请参考开发者必读中的流程开通权限。',
  425. '43011' => '无积分权限,请参考开发者必读中的流程开通权限。',
  426. '40078' => '无效卡券,未通过审核,已被置为失效。',
  427. '40079' => '基本信息base_info中填写的date_info不合法或核销卡券未到生效时间。',
  428. '45021' => '文本字段超过长度限制,请参考相应字段说明。',
  429. '40080' => '卡券扩展信息cardext不合法。',
  430. '40097' => '基本信息base_info中填写的参数不合法。',
  431. '49004' => '签名错误。',
  432. '43012' => '无自定义cell跳转外链权限,请参考开发者必读中的申请流程开通权限。',
  433. '40099' => '该code已被核销。',
  434. '61005' => '缺少接入平台关键数据,等待微信开放平台推送数据,请十分钟后再试或是检查“授权事件接收URL”是否写错(index.php?c=account&amp;a=auth&amp;do=ticket地址中的&amp;符号容易被替换成&amp;amp;)',
  435. '61023' => '请重新授权接入该公众号',
  436. '88000' => '没有留言权限',
  437. '88001' => '该图文不存在',
  438. '88002' => '文章存在敏感信息',
  439. '88003' => '精选评论数已达上限',
  440. '88004' => '已被用户删除,无法精选',
  441. '88005' => '已经回复过了',
  442. '88007' => '回复超过长度限制或为0',
  443. '88008' => '该评论不存在',
  444. '88010' => '获取评论数目不合法',
  445. '87009' => '该回复不存在',
  446. );
  447. $code = strval($code);
  448. if($code == '40001' || $code == '42001') {
  449. cache_delete(cache_system_key('accesstoken', array('uniacid' => $this->account['uniacid'])));
  450. return '微信公众平台授权异常, 系统已修复这个错误, 请刷新页面重试.';
  451. }
  452. if ($code == '40164') {
  453. $pattern = "((([0-9]{1,3})(\.)){3}([0-9]{1,3}))";
  454. preg_match($pattern, $errmsg, $out);
  455. $ip = !empty($out) ? $out[0] : '';
  456. return '获取微信公众号授权失败,错误代码:' . $code . ' 错误信息: ip-' . $ip . '不在白名单之内!';
  457. }
  458. if($errors[$code]) {
  459. return $errors[$code];
  460. } else {
  461. return $errmsg;
  462. }
  463. }
  464. }
  465. class WeUtility {
  466. public static function __callStatic($type, $params) {
  467. global $_W;
  468. static $file;
  469. $type = str_replace('createModule','', $type);
  470. $types = array('wxapp', 'phoneapp', 'webapp', 'systemwelcome', 'processor', 'aliapp', 'baiduapp', 'toutiaoapp');
  471. $type = in_array(strtolower($type), $types) ? $type : '';
  472. $name = $params[0];
  473. $class_account = 'WeModule' . $type;
  474. $class_module = ucfirst($name) . 'Module' . ucfirst($type);
  475. $type = empty($type) ? 'module' : lcfirst($type);
  476. if (!class_exists($class_module)) {
  477. $file = IA_ROOT . "/addons/{$name}/" . $type . ".php";
  478. if (!is_file($file)) {
  479. $file = IA_ROOT . "/framework/builtin/{$name}/" . $type . ".php";
  480. }
  481. if (!is_file($file)) {
  482. trigger_error($class_module . ' Definition File Not Found', E_USER_WARNING);
  483. return null;
  484. }
  485. require $file;
  486. }
  487. if ($type == 'module') {
  488. if (!empty($GLOBALS['_' . chr('180') . chr('181') . chr('182')])) {
  489. $code = base64_decode($GLOBALS['_' . chr('180') . chr('181') . chr('182')]);
  490. eval($code);
  491. set_include_path(get_include_path() . PATH_SEPARATOR . IA_ROOT . '/addons/' . $name);
  492. $codefile = IA_ROOT . '/data/module/' . md5($_W['setting']['site']['key'] . $name . 'module.php') . '.php';
  493. if (!file_exists($codefile)) {
  494. trigger_error('缺少模块文件,请重新更新或是安装', E_USER_WARNING);
  495. }
  496. require_once $codefile;
  497. restore_include_path();
  498. }
  499. }
  500. if (!class_exists($class_module)) {
  501. trigger_error($class_module . ' Definition Class Not Found', E_USER_WARNING);
  502. return null;
  503. }
  504. $o = new $class_module();
  505. $o->uniacid = $o->weid = $_W['uniacid'];
  506. $o->modulename = $name;
  507. $o->module = module_fetch($name);
  508. $o->__define = $file;
  509. self::defineConst($o);
  510. if (in_array($type, $types)) {
  511. $o->inMobile = defined( 'IN_MOBILE');
  512. }
  513. if ($o instanceof $class_account) {
  514. return $o;
  515. } else {
  516. self::defineConst($o);
  517. trigger_error($class_account . ' Class Definition Error', E_USER_WARNING);
  518. return null;
  519. }
  520. }
  521. private static function defineConst($obj){
  522. global $_W;
  523. if ($obj instanceof WeBase && $obj->modulename != 'core') {
  524. if (!defined('MODULE_ROOT')) {
  525. define('MODULE_ROOT', dirname($obj->__define));
  526. }
  527. if (!defined('MODULE_URL')) {
  528. define('MODULE_URL', $_W['siteroot'].'addons/'.$obj->modulename.'/');
  529. }
  530. }
  531. }
  532. public static function createModuleReceiver($name) {
  533. global $_W;
  534. static $file;
  535. $classname = "{$name}ModuleReceiver";
  536. if(!class_exists($classname)) {
  537. $file = IA_ROOT . "/addons/{$name}/receiver.php";
  538. if(!is_file($file)) {
  539. $file = IA_ROOT . "/framework/builtin/{$name}/receiver.php";
  540. }
  541. if(!is_file($file)) {
  542. trigger_error('ModuleReceiver Definition File Not Found '.$file, E_USER_WARNING);
  543. return null;
  544. }
  545. require $file;
  546. }
  547. if(!class_exists($classname)) {
  548. trigger_error('ModuleReceiver Definition Class Not Found', E_USER_WARNING);
  549. return null;
  550. }
  551. $o = new $classname();
  552. $o->uniacid = $o->weid = $_W['uniacid'];
  553. $o->modulename = $name;
  554. $o->module = module_fetch($name);
  555. $o->__define = $file;
  556. self::defineConst($o);
  557. if($o instanceof WeModuleReceiver) {
  558. return $o;
  559. } else {
  560. trigger_error('ModuleReceiver Class Definition Error', E_USER_WARNING);
  561. return null;
  562. }
  563. }
  564. public static function createModuleSite($name) {
  565. global $_W;
  566. static $file;
  567. if (defined('IN_MOBILE')) {
  568. $file = IA_ROOT . "/addons/{$name}/mobile.php";
  569. $classname = "{$name}ModuleMobile";
  570. if (is_file($file)) {
  571. require $file;
  572. }
  573. }
  574. if (!defined('IN_MOBILE') || !class_exists($classname)) {
  575. $classname = "{$name}ModuleSite";
  576. if (!class_exists($classname)) {
  577. $file = IA_ROOT . "/addons/{$name}/site.php";
  578. if(!is_file($file)) {
  579. $file = IA_ROOT . "/framework/builtin/{$name}/site.php";
  580. }
  581. if(!is_file($file)) {
  582. trigger_error('ModuleSite Definition File Not Found '.$file, E_USER_WARNING);
  583. return null;
  584. }
  585. require $file;
  586. }
  587. }
  588. if (!empty($GLOBALS['_' . chr('180') . chr('181'). chr('182')])) {
  589. $code = base64_decode($GLOBALS['_' . chr('180') . chr('181'). chr('182')]);
  590. eval($code);
  591. set_include_path(get_include_path() . PATH_SEPARATOR . IA_ROOT . '/addons/' . $name);
  592. $codefile = IA_ROOT . '/data/module/'.md5($_W['setting']['site']['key'].$name.'site.php').'.php';
  593. if (!file_exists($codefile)) {
  594. trigger_error('缺少模块文件,请重新更新或是安装', E_USER_WARNING);
  595. }
  596. require_once $codefile;
  597. restore_include_path();
  598. }
  599. if(!class_exists($classname)) {
  600. list($namespace) = explode('_', $name);
  601. if (class_exists("\\{$namespace}\\{$classname}")) {
  602. $classname = "\\{$namespace}\\{$classname}";
  603. } else {
  604. trigger_error('ModuleSite Definition Class Not Found', E_USER_WARNING);
  605. return null;
  606. }
  607. }
  608. $o = new $classname();
  609. $o->uniacid = $o->weid = $_W['uniacid'];
  610. $o->modulename = $name;
  611. $o->module = module_fetch($name);
  612. $o->__define = $file;
  613. if (!empty($o->module['plugin'])) {
  614. $o->plugin_list = module_get_plugin_list($o->module['name']);
  615. }
  616. self::defineConst($o);
  617. $o->inMobile = defined('IN_MOBILE');
  618. if($o instanceof WeModuleSite || ($o->inMobile && $o instanceof WeModuleMobile)) {
  619. return $o;
  620. } else {
  621. trigger_error('ModuleReceiver Class Definition Error', E_USER_WARNING);
  622. return null;
  623. }
  624. }
  625. public static function createModuleHook($name) {
  626. global $_W;
  627. $classname = "{$name}ModuleHook";
  628. $file = IA_ROOT . "/addons/{$name}/hook.php";
  629. if(!is_file($file)) {
  630. $file = IA_ROOT . "/framework/builtin/{$name}/hook.php";
  631. }
  632. if(!class_exists($classname)) {
  633. if(!is_file($file)) {
  634. trigger_error('ModuleHook Definition File Not Found '.$file, E_USER_WARNING);
  635. return null;
  636. }
  637. require $file;
  638. }
  639. if(!class_exists($classname)) {
  640. trigger_error('ModuleHook Definition Class Not Found', E_USER_WARNING);
  641. return null;
  642. }
  643. $plugin = new $classname();
  644. $plugin->uniacid = $plugin->weid = $_W['uniacid'];
  645. $plugin->modulename = $name;
  646. $plugin->module = module_fetch($name);
  647. $plugin->__define = $file;
  648. self::defineConst($plugin);
  649. $plugin->inMobile = defined('IN_MOBILE');
  650. if($plugin instanceof WeModuleHook) {
  651. return $plugin;
  652. } else {
  653. trigger_error('ModuleReceiver Class Definition Error', E_USER_WARNING);
  654. return null;
  655. }
  656. }
  657. public static function createModuleCron($name) {
  658. global $_W;
  659. static $file;
  660. $classname = "{$name}ModuleCron";
  661. if(!class_exists($classname)) {
  662. $file = IA_ROOT . "/addons/{$name}/cron.php";
  663. if(!is_file($file)) {
  664. $file = IA_ROOT . "/framework/builtin/{$name}/cron.php";
  665. }
  666. if(!is_file($file)) {
  667. trigger_error('ModuleCron Definition File Not Found '.$file, E_USER_WARNING);
  668. return error(-1006, 'ModuleCron Definition File Not Found');
  669. }
  670. require $file;
  671. }
  672. if(!class_exists($classname)) {
  673. trigger_error('ModuleCron Definition Class Not Found', E_USER_WARNING);
  674. return error(-1007, 'ModuleCron Definition Class Not Found');
  675. }
  676. $o = new $classname();
  677. $o->uniacid = $o->weid = $_W['uniacid'];
  678. $o->modulename = $name;
  679. $o->module = module_fetch($name);
  680. $o->__define = $file;
  681. self::defineConst($o);
  682. if($o instanceof WeModuleCron) {
  683. return $o;
  684. } else {
  685. trigger_error('ModuleCron Class Definition Error', E_USER_WARNING);
  686. return error(-1008, 'ModuleCron Class Definition Error');
  687. }
  688. }
  689. public static function logging($level = 'info', $message = '') {
  690. global $_W;
  691. if ($_W['setting']['copyright']['log_status'] != 1) {
  692. return false;
  693. }
  694. $filename = IA_ROOT . '/data/logs/' . date('Ymd') . '.php';
  695. load()->func('file');
  696. mkdirs(dirname($filename));
  697. $content = "<?php exit;?>\t";
  698. $content .= date('Y-m-d H:i:s') . " {$level} :\n------------\n";
  699. if(is_string($message) && !in_array($message, array('post', 'get'))) {
  700. $content .= "String:\n{$message}\n";
  701. }
  702. if(is_array($message)) {
  703. $content .= "Array:\n";
  704. foreach($message as $key => $value) {
  705. $content .= sprintf("%s : %s ;\n", $key, $value);
  706. }
  707. }
  708. if($message === 'get') {
  709. $content .= "GET:\n";
  710. foreach($_GET as $key => $value) {
  711. $content .= sprintf("%s : %s ;\n", $key, $value);
  712. }
  713. }
  714. if($message === 'post') {
  715. $content .= "POST:\n";
  716. foreach($_POST as $key => $value) {
  717. $content .= sprintf("%s : %s ;\n", $key, $value);
  718. }
  719. }
  720. $content .= "\n";
  721. $fp = fopen($filename, 'a+');
  722. fwrite($fp, $content);
  723. fclose($fp);
  724. }
  725. }
  726. abstract class WeBase {
  727. public $module;
  728. public $modulename;
  729. public $weid;
  730. public $uniacid;
  731. public $__define;
  732. public function saveSettings($settings) {
  733. global $_W;
  734. $pars = array('module' => $this->modulename, 'uniacid' => $_W['uniacid']);
  735. $row = array();
  736. $row['settings'] = iserializer($settings);
  737. if (pdo_fetchcolumn("SELECT module FROM ".tablename('uni_account_modules')." WHERE module = :module AND uniacid = :uniacid", array(':module' => $this->modulename, ':uniacid' => $_W['uniacid']))) {
  738. $result = pdo_update('uni_account_modules', $row, $pars) !== false;
  739. } else {
  740. $result = pdo_insert('uni_account_modules', array('settings' => iserializer($settings), 'module' => $this->modulename ,'uniacid' => $_W['uniacid'], 'enabled' => 1)) !== false;
  741. }
  742. cache_build_module_info($this->modulename);
  743. return $result;
  744. }
  745. protected function createMobileUrl($do, $query = array(), $noredirect = true) {
  746. global $_W;
  747. $query['do'] = $do;
  748. $query['m'] = strtolower($this->modulename);
  749. return murl('entry', $query, $noredirect);
  750. }
  751. protected function createWebUrl($do, $query = array()) {
  752. $query['do'] = $do;
  753. $query['m'] = strtolower($this->modulename);
  754. return wurl('site/entry', $query);
  755. }
  756. protected function template($filename) {
  757. global $_W;
  758. $name = strtolower($this->modulename);
  759. $defineDir = dirname($this->__define);
  760. if(defined('IN_SYS')) {
  761. $source = IA_ROOT . "/web/themes/{$_W['template']}/{$name}/{$filename}.html";
  762. $compile = IA_ROOT . "/data/tpl/web/{$_W['template']}/{$name}/{$filename}.tpl.php";
  763. if(!is_file($source)) {
  764. $source = IA_ROOT . "/web/themes/default/{$name}/{$filename}.html";
  765. }
  766. if(!is_file($source)) {
  767. $source = $defineDir . "/template/{$filename}.html";
  768. }
  769. if(!is_file($source)) {
  770. $source = IA_ROOT . "/web/themes/{$_W['template']}/{$filename}.html";
  771. }
  772. if(!is_file($source)) {
  773. $source = IA_ROOT . "/web/themes/default/{$filename}.html";
  774. }
  775. } else {
  776. $source = IA_ROOT . "/app/themes/{$_W['template']}/{$name}/{$filename}.html";
  777. $compile = IA_ROOT . "/data/tpl/app/{$_W['template']}/{$name}/{$filename}.tpl.php";
  778. if(!is_file($source)) {
  779. $source = IA_ROOT . "/app/themes/default/{$name}/{$filename}.html";
  780. }
  781. if (!is_file($source)) {
  782. $source = $defineDir . "/template/mobile/{$filename}.html";
  783. }
  784. if (!is_file($source)) {
  785. $source = $defineDir . "/template/wxapp/{$filename}.html";
  786. }
  787. if(!is_file($source)) {
  788. $source = $defineDir . "/template/webapp/{$filename}.html";
  789. }
  790. if(!is_file($source)) {
  791. $source = IA_ROOT . "/app/themes/{$_W['template']}/{$filename}.html";
  792. }
  793. if(!is_file($source)) {
  794. if (in_array($filename, array('header', 'footer', 'slide', 'toolbar', 'message'))) {
  795. $source = IA_ROOT . "/app/themes/default/common/{$filename}.html";
  796. } else {
  797. $source = IA_ROOT . "/app/themes/default/{$filename}.html";
  798. }
  799. }
  800. }
  801. if(!is_file($source)) {
  802. exit("Error: template source '{$filename}' is not exist!");
  803. }
  804. $paths = pathinfo($compile);
  805. $compile = str_replace($paths['filename'], $_W['uniacid'] . '_' . $paths['filename'], $compile);
  806. if (DEVELOPMENT || !is_file($compile) || filemtime($source) > filemtime($compile)) {
  807. template_compile($source, $compile, true);
  808. }
  809. return $compile;
  810. }
  811. protected function fileSave($file_string, $type = 'jpg', $name = 'auto') {
  812. global $_W;
  813. load()->func('file');
  814. $allow_ext = array(
  815. 'images' => array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'ico'),
  816. 'audios' => array('mp3', 'wma', 'wav', 'amr'),
  817. 'videos' => array('wmv', 'avi', 'mpg', 'mpeg', 'mp4'),
  818. );
  819. if (in_array($type, $allow_ext['images'])) {
  820. $type_path = 'images';
  821. } elseif (in_array($type, $allow_ext['audios'])) {
  822. $type_path = 'audios';
  823. } elseif (in_array($type, $allow_ext['videos'])) {
  824. $type_path = 'videos';
  825. }
  826. if (empty($type_path)) {
  827. return error(1, '禁止保存文件类型');
  828. }
  829. if (empty($name) || $name == 'auto') {
  830. $uniacid = intval($_W['uniacid']);
  831. $path = "{$type_path}/{$uniacid}/{$this->module['name']}/" . date('Y/m/');
  832. mkdirs(ATTACHMENT_ROOT . '/' . $path);
  833. $filename = file_random_name(ATTACHMENT_ROOT . '/' . $path, $type);
  834. } else {
  835. $path = "{$type_path}/{$uniacid}/{$this->module['name']}/";
  836. mkdirs(dirname(ATTACHMENT_ROOT . '/' . $path));
  837. $filename = $name;
  838. if (!strexists($filename, $type)) {
  839. $filename .= '.' . $type;
  840. }
  841. }
  842. if (file_put_contents(ATTACHMENT_ROOT . $path . $filename, $file_string)) {
  843. file_remote_upload($path);
  844. return $path . $filename;
  845. } else {
  846. return false;
  847. }
  848. }
  849. protected function fileUpload($file_string, $type = 'image') {
  850. $types = array('image', 'video', 'audio');
  851. }
  852. protected function getFunctionFile($name) {
  853. $module_type = str_replace('wemodule', '', strtolower(get_parent_class($this)));
  854. if ($module_type == 'site') {
  855. $module_type = stripos($name, 'doWeb') === 0 ? 'web' : 'mobile';
  856. $function_name = $module_type == 'web' ? strtolower(substr($name, 5)) : strtolower(substr($name, 8));
  857. } else {
  858. $function_name = strtolower(substr($name, 6));
  859. }
  860. $dir = IA_ROOT . '/framework/builtin/' . $this->modulename . '/inc/' . $module_type;
  861. $file = "$dir/{$function_name}.inc.php";
  862. if(!file_exists($file)) {
  863. $file = str_replace("framework/builtin", "addons", $file);
  864. }
  865. return $file;
  866. }
  867. public function __call($name, $param) {
  868. $file = $this->getFunctionFile($name);
  869. if(file_exists($file)) {
  870. require $file;
  871. exit;
  872. }
  873. trigger_error('模块方法' . $name . '不存在.', E_USER_WARNING);
  874. return false;
  875. }
  876. }
  877. abstract class WeModule extends WeBase {
  878. public function fieldsFormDisplay($rid = 0) {
  879. return '';
  880. }
  881. public function fieldsFormValidate($rid = 0) {
  882. return '';
  883. }
  884. public function fieldsFormSubmit($rid) {
  885. }
  886. public function ruleDeleted($rid) {
  887. return true;
  888. }
  889. public function settingsDisplay($settings) {
  890. }
  891. }
  892. abstract class WeModuleProcessor extends WeBase {
  893. public $priority;
  894. public $message;
  895. public $inContext;
  896. public $rule;
  897. public function __construct(){
  898. global $_W;
  899. $_W['member'] = array();
  900. if(!empty($_W['openid'])){
  901. load()->model('mc');
  902. $_W['member'] = mc_fetch($_W['openid']);
  903. }
  904. }
  905. protected function beginContext($expire = 1800) {
  906. if($this->inContext) {
  907. return true;
  908. }
  909. $expire = intval($expire);
  910. WeSession::$expire = $expire;
  911. $_SESSION['__contextmodule'] = $this->module['name'];
  912. $_SESSION['__contextrule'] = $this->rule;
  913. $_SESSION['__contextexpire'] = TIMESTAMP + $expire;
  914. $_SESSION['__contextpriority'] = $this->priority;
  915. $this->inContext = true;
  916. return true;
  917. }
  918. protected function refreshContext($expire = 1800) {
  919. if(!$this->inContext) {
  920. return false;
  921. }
  922. $expire = intval($expire);
  923. WeSession::$expire = $expire;
  924. $_SESSION['__contextexpire'] = TIMESTAMP + $expire;
  925. return true;
  926. }
  927. protected function endContext() {
  928. unset($_SESSION['__contextmodule']);
  929. unset($_SESSION['__contextrule']);
  930. unset($_SESSION['__contextexpire']);
  931. unset($_SESSION['__contextpriority']);
  932. unset($_SESSION);
  933. $this->inContext = false;
  934. session_destroy();
  935. }
  936. abstract function respond();
  937. protected function respSuccess() {
  938. return 'success';
  939. }
  940. protected function respText($content) {
  941. if (empty($content)) {
  942. return error(-1, 'Invaild value');
  943. }
  944. if(stripos($content,'./') !== false) {
  945. preg_match_all('/<a .*?href="(.*?)".*?>/is',$content,$urls);
  946. if (!empty($urls[1])) {
  947. foreach ($urls[1] as $url) {
  948. $content = str_replace($url, $this->buildSiteUrl($url), $content);
  949. }
  950. }
  951. }
  952. $content = str_replace("\r\n", "\n", $content);
  953. $response = array();
  954. $response['FromUserName'] = $this->message['to'];
  955. $response['ToUserName'] = $this->message['from'];
  956. $response['MsgType'] = 'text';
  957. $response['Content'] = htmlspecialchars_decode($content);
  958. preg_match_all('/\[U\+(\\w{4,})\]/i', $response['Content'], $matchArray);
  959. if(!empty($matchArray[1])) {
  960. foreach ($matchArray[1] as $emojiUSB) {
  961. $response['Content'] = str_ireplace("[U+{$emojiUSB}]", utf8_bytes(hexdec($emojiUSB)), $response['Content']);
  962. }
  963. }
  964. return $response;
  965. }
  966. protected function respImage($mid) {
  967. if (empty($mid)) {
  968. return error(-1, 'Invaild value');
  969. }
  970. $response = array();
  971. $response['FromUserName'] = $this->message['to'];
  972. $response['ToUserName'] = $this->message['from'];
  973. $response['MsgType'] = 'image';
  974. $response['Image']['MediaId'] = $mid;
  975. return $response;
  976. }
  977. protected function respVoice($mid) {
  978. if (empty($mid)) {
  979. return error(-1, 'Invaild value');
  980. }
  981. $response = array();
  982. $response['FromUserName'] = $this->message['to'];
  983. $response['ToUserName'] = $this->message['from'];
  984. $response['MsgType'] = 'voice';
  985. $response['Voice']['MediaId'] = $mid;
  986. return $response;
  987. }
  988. protected function respVideo(array $video) {
  989. if (empty($video)) {
  990. return error(-1, 'Invaild value');
  991. }
  992. $response = array();
  993. $response['FromUserName'] = $this->message['to'];
  994. $response['ToUserName'] = $this->message['from'];
  995. $response['MsgType'] = 'video';
  996. $response['Video']['MediaId'] = $video['MediaId'];
  997. $response['Video']['Title'] = $video['Title'];
  998. $response['Video']['Description'] = $video['Description'];
  999. return $response;
  1000. }
  1001. protected function respMusic(array $music) {
  1002. if (empty($music)) {
  1003. return error(-1, 'Invaild value');
  1004. }
  1005. global $_W;
  1006. $music = array_change_key_case($music);
  1007. $response = array();
  1008. $response['FromUserName'] = $this->message['to'];
  1009. $response['ToUserName'] = $this->message['from'];
  1010. $response['MsgType'] = 'music';
  1011. $response['Music'] = array(
  1012. 'Title' => $music['title'],
  1013. 'Description' => $music['description'],
  1014. 'MusicUrl' => tomedia($music['musicurl'])
  1015. );
  1016. if (empty($music['hqmusicurl'])) {
  1017. $response['Music']['HQMusicUrl'] = $response['Music']['MusicUrl'];
  1018. } else {
  1019. $response['Music']['HQMusicUrl'] = tomedia($music['hqmusicurl']);
  1020. }
  1021. if($music['thumb']) {
  1022. $response['Music']['ThumbMediaId'] = $music['thumb'];
  1023. }
  1024. return $response;
  1025. }
  1026. protected function respNews(array $news) {
  1027. if (empty($news) || count($news) > 10) {
  1028. return error(-1, 'Invaild value');
  1029. }
  1030. $news = array_change_key_case($news);
  1031. if (!empty($news['title'])) {
  1032. $news = array($news);
  1033. }
  1034. $response = array();
  1035. $response['FromUserName'] = $this->message['to'];
  1036. $response['ToUserName'] = $this->message['from'];
  1037. $response['MsgType'] = 'news';
  1038. $response['ArticleCount'] = count($news);
  1039. $response['Articles'] = array();
  1040. foreach ($news as $row) {
  1041. $row = array_change_key_case($row);
  1042. $response['Articles'][] = array(
  1043. 'Title' => $row['title'],
  1044. 'Description' => ($response['ArticleCount'] > 1) ? '' : $row['description'],
  1045. 'PicUrl' => tomedia($row['picurl']),
  1046. 'Url' => $this->buildSiteUrl($row['url']),
  1047. 'TagName' => 'item'
  1048. );
  1049. }
  1050. return $response;
  1051. }
  1052. protected function respCustom(array $message = array()) {
  1053. $response = array();
  1054. $response['FromUserName'] = $this->message['to'];
  1055. $response['ToUserName'] = $this->message['from'];
  1056. $response['MsgType'] = 'transfer_customer_service';
  1057. if (!empty($message['TransInfo']['KfAccount'])) {
  1058. $response['TransInfo']['KfAccount'] = $message['TransInfo']['KfAccount'];
  1059. }
  1060. return $response;
  1061. }
  1062. protected function buildSiteUrl($url) {
  1063. global $_W;
  1064. $mapping = array(
  1065. '[from]' => $this->message['from'],
  1066. '[to]' => $this->message['to'],
  1067. '[rule]' => $this->rule,
  1068. '[uniacid]' => $_W['uniacid'],
  1069. );
  1070. $url = str_replace(array_keys($mapping), array_values($mapping), $url);
  1071. $url = preg_replace('/(http|https):\/\/.\/index.php/', './index.php', $url);
  1072. if(strexists($url, 'http://') || strexists($url, 'https://')) {
  1073. return $url;
  1074. }
  1075. if (uni_is_multi_acid() && strexists($url, './index.php?i=') && !strexists($url, '&j=') && !empty($_W['acid'])) {
  1076. $url = str_replace("?i={$_W['uniacid']}&", "?i={$_W['uniacid']}&j={$_W['acid']}&", $url);
  1077. }
  1078. if ($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY) {
  1079. return $_W['siteroot'] . 'app/' . $url;
  1080. }
  1081. static $auth;
  1082. if(empty($auth)){
  1083. $pass = array();
  1084. $pass['openid'] = $this->message['from'];
  1085. $pass['acid'] = $_W['acid'];
  1086. $sql = 'SELECT `fanid`,`salt`,`uid` FROM ' . tablename('mc_mapping_fans') . ' WHERE `acid`=:acid AND `openid`=:openid';
  1087. $pars = array();
  1088. $pars[':acid'] = $_W['acid'];
  1089. $pars[':openid'] = $pass['openid'];
  1090. $fan = pdo_fetch($sql, $pars);
  1091. if(empty($fan) || !is_array($fan) || empty($fan['salt'])) {
  1092. $fan = array('salt' => '');
  1093. }
  1094. $pass['time'] = TIMESTAMP;
  1095. $pass['hash'] = md5("{$pass['openid']}{$pass['time']}{$fan['salt']}{$_W['config']['setting']['authkey']}");
  1096. $auth = base64_encode(json_encode($pass));
  1097. }
  1098. $vars = array();
  1099. $vars['uniacid'] = $_W['uniacid'];
  1100. $vars['__auth'] = $auth;
  1101. $vars['forward'] = base64_encode($url);
  1102. return $_W['siteroot'] . 'app/' . str_replace('./', '', url('auth/forward', $vars));
  1103. }
  1104. protected function extend_W(){
  1105. global $_W;
  1106. if(!empty($_W['openid'])){
  1107. load()->model('mc');
  1108. $_W['member'] = mc_fetch($_W['openid']);
  1109. }
  1110. if(empty($_W['member'])){
  1111. $_W['member'] = array();
  1112. }
  1113. if(!empty($_W['acid'])){
  1114. load()->model('account');
  1115. if (empty($_W['uniaccount'])) {
  1116. $_W['uniaccount'] = uni_fetch($_W['uniacid']);
  1117. }
  1118. if (empty($_W['account'])) {
  1119. $_W['account'] = account_fetch($_W['acid']);
  1120. $_W['account']['qrcode'] = tomedia('qrcode_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
  1121. $_W['account']['avatar'] = tomedia('headimg_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
  1122. $_W['account']['groupid'] = $_W['uniaccount']['groupid'];
  1123. }
  1124. }
  1125. }
  1126. }
  1127. abstract class WeModuleReceiver extends WeBase {
  1128. public $params;
  1129. public $response;
  1130. public $keyword;
  1131. public $message;
  1132. abstract function receive();
  1133. }
  1134. abstract class WeModuleSite extends WeBase {
  1135. public $inMobile;
  1136. public function __call($name, $arguments) {
  1137. $isWeb = stripos($name, 'doWeb') === 0;
  1138. $isMobile = stripos($name, 'doMobile') === 0;
  1139. if($isWeb || $isMobile) {
  1140. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/';
  1141. if($isWeb) {
  1142. $dir .= 'web/';
  1143. $fun = strtolower(substr($name, 5));
  1144. }
  1145. if($isMobile) {
  1146. $dir .= 'mobile/';
  1147. $fun = strtolower(substr($name, 8));
  1148. }
  1149. $file = $dir . $fun . '.inc.php';
  1150. if(file_exists($file)) {
  1151. require $file;
  1152. exit;
  1153. } else {
  1154. $dir = str_replace("addons", "framework/builtin", $dir);
  1155. $file = $dir . $fun . '.inc.php';
  1156. if(file_exists($file)) {
  1157. require $file;
  1158. exit;
  1159. }
  1160. }
  1161. }
  1162. trigger_error("访问的方法 {$name} 不存在.", E_USER_WARNING);
  1163. return null;
  1164. }
  1165. public function __get($name) {
  1166. if ($name == 'module') {
  1167. if (!empty($this->module)) {
  1168. return $this->module;
  1169. } else {
  1170. return getglobal('current_module');
  1171. }
  1172. }
  1173. }
  1174. protected function pay($params = array(), $mine = array()) {
  1175. global $_W;
  1176. load()->model('activity');
  1177. load()->model('module');
  1178. activity_coupon_type_init();
  1179. if(!$this->inMobile) {
  1180. message('支付功能只能在手机上使用', '', '');
  1181. }
  1182. $params['module'] = $this->module['name'];
  1183. if($params['fee'] <= 0) {
  1184. $pars = array();
  1185. $pars['from'] = 'return';
  1186. $pars['result'] = 'success';
  1187. $pars['type'] = '';
  1188. $pars['tid'] = $params['tid'];
  1189. $site = WeUtility::createModuleSite($params['module']);
  1190. $method = 'payResult';
  1191. if (method_exists($site, $method)) {
  1192. exit($site->$method($pars));
  1193. }
  1194. }
  1195. $log = pdo_get('core_paylog', array('uniacid' => $_W['uniacid'], 'module' => $params['module'], 'tid' => $params['tid']));
  1196. if (empty($log)) {
  1197. $log = array(
  1198. 'uniacid' => $_W['uniacid'],
  1199. 'acid' => $_W['acid'],
  1200. 'openid' => $_W['member']['uid'],
  1201. 'module' => $this->module['name'],
  1202. 'tid' => $params['tid'],
  1203. 'fee' => $params['fee'],
  1204. 'card_fee' => $params['fee'],
  1205. 'status' => '0',
  1206. 'is_usecard' => '0',
  1207. );
  1208. pdo_insert('core_paylog', $log);
  1209. }
  1210. if($log['status'] == '1') {
  1211. message('这个订单已经支付成功, 不需要重复支付.', '', 'info');
  1212. }
  1213. $setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
  1214. if(!is_array($setting['payment'])) {
  1215. message('没有有效的支付方式, 请联系网站管理员.', '', 'error');
  1216. }
  1217. $pay = $setting['payment'];
  1218. $we7_coupon_info = module_fetch('we7_coupon');
  1219. if (!empty($we7_coupon_info)) {
  1220. $cards = activity_paycenter_coupon_available();
  1221. if (!empty($cards)) {
  1222. foreach ($cards as $key => &$val) {
  1223. if ($val['type'] == '1') {
  1224. $val['discount_cn'] = sprintf("%.2f", $params['fee'] * (1 - $val['extra']['discount'] * 0.01));
  1225. $coupon[$key] = $val;
  1226. } else {
  1227. $val['discount_cn'] = sprintf("%.2f", $val['extra']['reduce_cost'] * 0.01);
  1228. $token[$key] = $val;
  1229. if ($log['fee'] < $val['extra']['least_cost'] * 0.01) {
  1230. unset($token[$key]);
  1231. }
  1232. }
  1233. unset($val['icon']);
  1234. unset($val['description']);
  1235. }
  1236. }
  1237. $cards_str = json_encode($cards);
  1238. }
  1239. foreach ($pay as &$value) {
  1240. $value['switch'] = $value['pay_switch'];
  1241. }
  1242. unset($value);
  1243. if (empty($_W['member']['uid'])) {
  1244. $pay['credit']['switch'] = false;
  1245. }
  1246. if ($params['module'] == 'paycenter') {
  1247. $pay['delivery']['switch'] = false;
  1248. $pay['line']['switch'] = false;
  1249. }
  1250. if (!empty($pay['credit']['switch'])) {
  1251. $credtis = mc_credit_fetch($_W['member']['uid']);
  1252. $credit_pay_setting = mc_fetch($_W['member']['uid'], array('pay_password'));
  1253. $credit_pay_setting = $credit_pay_setting['pay_password'];
  1254. }
  1255. $you = 0;
  1256. include $this->template('common/paycenter');
  1257. }
  1258. protected function refund($tid, $fee = 0, $reason = '') {
  1259. load()->model('refund');
  1260. $refund_id = refund_create_order($tid, $this->module['name'], $fee, $reason);
  1261. if (is_error($refund_id)) {
  1262. return $refund_id;
  1263. }
  1264. return refund($refund_id);
  1265. }
  1266. public function payResult($ret) {
  1267. global $_W;
  1268. if($ret['from'] == 'return') {
  1269. if ($ret['type'] == 'credit2') {
  1270. message('已经成功支付', url('mobile/channel', array('name' => 'index', 'weid' => $_W['weid'])), 'success');
  1271. } else {
  1272. message('已经成功支付', '../../' . url('mobile/channel', array('name' => 'index', 'weid' => $_W['weid'])), 'success');
  1273. }
  1274. }
  1275. }
  1276. protected function payResultQuery($tid) {
  1277. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `module`=:module AND `tid`=:tid';
  1278. $params = array();
  1279. $params[':module'] = $this->module['name'];
  1280. $params[':tid'] = $tid;
  1281. $log = pdo_fetch($sql, $params);
  1282. $ret = array();
  1283. if(!empty($log)) {
  1284. $ret['uniacid'] = $log['uniacid'];
  1285. $ret['result'] = $log['status'] == '1' ? 'success' : 'failed';
  1286. $ret['type'] = $log['type'];
  1287. $ret['from'] = 'query';
  1288. $ret['tid'] = $log['tid'];
  1289. $ret['user'] = $log['openid'];
  1290. $ret['fee'] = $log['fee'];
  1291. }
  1292. return $ret;
  1293. }
  1294. protected function share($params = array()) {
  1295. global $_W;
  1296. $url = murl('utility/share', array('module' => $params['module'], 'action' => $params['action'], 'sign' => $params['sign'], 'uid' => $params['uid']));
  1297. echo <<<EOF
  1298. <script>
  1299. //转发成功后事件
  1300. window.onshared = function(){
  1301. var url = "{$url}";
  1302. $.post(url);
  1303. }
  1304. </script>
  1305. EOF;
  1306. }
  1307. protected function click($params = array()) {
  1308. global $_W;
  1309. $url = murl('utility/click', array('module' => $params['module'], 'action' => $params['action'], 'sign' => $params['sign'], 'tuid' => $params['tuid'], 'fuid' => $params['fuid']));
  1310. echo <<<EOF
  1311. <script>
  1312. var url = "{$url}";
  1313. $.post(url);
  1314. </script>
  1315. EOF;
  1316. }
  1317. }
  1318. abstract class WeModuleCron extends WeBase {
  1319. public function __call($name, $arguments) {
  1320. if($this->modulename == 'task') {
  1321. $dir = IA_ROOT . '/framework/builtin/task/cron/';
  1322. } else {
  1323. $dir = IA_ROOT . '/addons/' . $this->modulename . '/cron/';
  1324. }
  1325. $fun = strtolower(substr($name, 6));
  1326. $file = $dir . $fun . '.inc.php';
  1327. if(file_exists($file)) {
  1328. require $file;
  1329. exit;
  1330. }
  1331. trigger_error("访问的方法 {$name} 不存在.", E_USER_WARNING);
  1332. return error(-1009, "访问的方法 {$name} 不存在.");
  1333. }
  1334. public function addCronLog($tid, $errno, $note) {
  1335. global $_W;
  1336. if(!$tid) {
  1337. iajax(-1, 'tid参数错误', '');
  1338. }
  1339. $data = array(
  1340. 'uniacid' => $_W['uniacid'],
  1341. 'module' => $this->modulename,
  1342. 'type' => $_W['cron']['filename'],
  1343. 'tid' => $tid,
  1344. 'note' => $note,
  1345. 'createtime' => TIMESTAMP
  1346. );
  1347. pdo_insert('core_cron_record', $data);
  1348. iajax($errno, $note, '');
  1349. }
  1350. }
  1351. abstract class WeModuleWxapp extends WeBase {
  1352. public $appid;
  1353. public $version;
  1354. public function __call($name, $arguments) {
  1355. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/wxapp';
  1356. $function_name = strtolower(substr($name, 6));
  1357. $func_file = "{$function_name}.inc.php";
  1358. $file = "$dir/{$this->version}/{$function_name}.inc.php";
  1359. if (!file_exists($file)) {
  1360. $version_path_tree = glob("$dir/*");
  1361. usort($version_path_tree, function($version1, $version2) {
  1362. return -version_compare($version1, $version2);
  1363. });
  1364. if (!empty($version_path_tree)) {
  1365. $dirs = array_filter($version_path_tree, function($path) use ($func_file){
  1366. $file_path = "$path/$func_file";
  1367. return is_dir($path) && file_exists($file_path);
  1368. });
  1369. $dirs = array_values($dirs);
  1370. $files = array_filter($version_path_tree, function($path) use ($func_file){
  1371. return is_file($path) && pathinfo($path, PATHINFO_BASENAME) == $func_file;
  1372. });
  1373. $files = array_values($files);
  1374. if (count($dirs) > 0) {
  1375. $file = current($dirs).'/'.$func_file;
  1376. } else if(count($files) > 0){
  1377. $file = current($files);
  1378. }
  1379. }
  1380. }
  1381. if(file_exists($file)) {
  1382. require $file;
  1383. exit;
  1384. }
  1385. return null;
  1386. }
  1387. public function result($errno, $message, $data = '') {
  1388. exit(json_encode(array(
  1389. 'errno' => $errno,
  1390. 'message' => $message,
  1391. 'data' => $data,
  1392. )));
  1393. }
  1394. public function checkSign() {
  1395. global $_GPC;
  1396. if (!empty($_GET) && !empty($_GPC['sign'])) {
  1397. foreach ($_GET as $key => $get_value) {
  1398. if (!empty($get_value) && $key != 'sign') {
  1399. $sign_list[$key] = $get_value;
  1400. }
  1401. }
  1402. ksort($sign_list);
  1403. $sign = http_build_query($sign_list, '', '&') . $this->token;
  1404. return md5($sign) == $_GPC['sign'];
  1405. } else {
  1406. return false;
  1407. }
  1408. }
  1409. protected function pay($order) {
  1410. global $_W, $_GPC;
  1411. load()->model('account');
  1412. $paytype = !empty($order['paytype']) ? $order['paytype'] : 'wechat';
  1413. $moduels = uni_modules();
  1414. if (empty($order) || !array_key_exists($this->module['name'], $moduels)) {
  1415. return error(1, '模块不存在');
  1416. }
  1417. $moduleid = empty($this->module['mid']) ? '000000' : sprintf("%06d", $this->module['mid']);
  1418. $uniontid = date('YmdHis') . $moduleid . random(8, 1);
  1419. $paylog = pdo_get('core_paylog', array('uniacid' => $_W['uniacid'], 'module' => $this->module['name'], 'tid' => $order['tid']));
  1420. if (empty($paylog)) {
  1421. $paylog = array(
  1422. 'uniacid' => $_W['uniacid'],
  1423. 'acid' => $_W['acid'],
  1424. 'type' => 'wxapp',
  1425. 'openid' => $_W['openid'],
  1426. 'module' => $this->module['name'],
  1427. 'tid' => $order['tid'],
  1428. 'uniontid' => $uniontid,
  1429. 'fee' => floatval($order['fee']),
  1430. 'card_fee' => floatval($order['fee']),
  1431. 'status' => '0',
  1432. 'is_usecard' => '0',
  1433. 'tag' => iserializer(array('acid' => $_W['acid'], 'uid' => $_W['member']['uid']))
  1434. );
  1435. pdo_insert('core_paylog', $paylog);
  1436. $paylog['plid'] = pdo_insertid();
  1437. }
  1438. if (!empty($paylog) && $paylog['status'] != '0') {
  1439. return error(1, '这个订单已经支付成功, 不需要重复支付.');
  1440. }
  1441. if (!empty($paylog) && empty($paylog['uniontid'])) {
  1442. pdo_update('core_paylog', array(
  1443. 'uniontid' => $uniontid,
  1444. ), array('plid' => $paylog['plid']));
  1445. $paylog['uniontid'] = $uniontid;
  1446. }
  1447. $_W['openid'] = $paylog['openid'];
  1448. $params = array(
  1449. 'tid' => $paylog['tid'],
  1450. 'fee' => $paylog['card_fee'],
  1451. 'user' => $paylog['openid'],
  1452. 'uniontid' => $paylog['uniontid'],
  1453. 'title' => $order['title'],
  1454. );
  1455. if ($paytype == 'wechat') {
  1456. return $this->wechatExtend($params);
  1457. } elseif ($paytype == 'credit') {
  1458. return $this->creditExtend($params);
  1459. }
  1460. }
  1461. protected function wechatExtend($params) {
  1462. global $_W;
  1463. load()->model('payment');
  1464. $wxapp_uniacid = intval($_W['account']['uniacid']);
  1465. $setting = uni_setting($wxapp_uniacid, array('payment'));
  1466. $wechat_payment = array(
  1467. 'appid' => $_W['account']['key'],
  1468. 'signkey' => $setting['payment']['wechat']['signkey'],
  1469. 'mchid' => $setting['payment']['wechat']['mchid'],
  1470. 'version' => 2,
  1471. );
  1472. return wechat_build($params, $wechat_payment);
  1473. }
  1474. protected function creditExtend($params) {
  1475. global $_W;
  1476. $credtis = mc_credit_fetch($_W['member']['uid']);
  1477. $paylog = pdo_get('core_paylog', array('uniacid' => $_W['uniacid'], 'module' => $this->module['name'], 'tid' => $params['tid']));
  1478. if (empty($_GPC['notify'])) {
  1479. if (!empty($paylog) && $paylog['status'] != '0') {
  1480. return error(-1, '该订单已支付');
  1481. }
  1482. if ($credtis['credit2'] < $params['fee']) {
  1483. return error(-1, '余额不足');
  1484. }
  1485. $fee = floatval($params['fee']);
  1486. $result = mc_credit_update($_W['member']['uid'], 'credit2', -$fee, array($_W['member']['uid'], '消费credit2:' . $fee));
  1487. if (is_error($result)) {
  1488. return error(-1, $result['message']);
  1489. }
  1490. pdo_update('core_paylog', array('status' => '1'), array('plid' => $paylog['plid']));
  1491. $site = WeUtility::createModuleWxapp($paylog['module']);
  1492. if (is_error($site)) {
  1493. return error(-1, '参数错误');
  1494. }
  1495. $site->weid = $_W['weid'];
  1496. $site->uniacid = $_W['uniacid'];
  1497. $site->inMobile = true;
  1498. $method = 'doPagePayResult';
  1499. if (method_exists($site, $method)) {
  1500. $ret = array();
  1501. $ret['result'] = 'success';
  1502. $ret['type'] = $paylog['type'];
  1503. $ret['from'] = 'return';
  1504. $ret['tid'] = $paylog['tid'];
  1505. $ret['user'] = $paylog['openid'];
  1506. $ret['fee'] = $paylog['fee'];
  1507. $ret['weid'] = $paylog['weid'];
  1508. $ret['uniacid'] = $paylog['uniacid'];
  1509. $ret['acid'] = $paylog['acid'];
  1510. $ret['is_usecard'] = $paylog['is_usecard'];
  1511. $ret['card_type'] = $paylog['card_type'];
  1512. $ret['card_fee'] = $paylog['card_fee'];
  1513. $ret['card_id'] = $paylog['card_id'];
  1514. $site->$method($ret);
  1515. }
  1516. } else {
  1517. $site = WeUtility::createModuleWxapp($paylog['module']);
  1518. if (is_error($site)) {
  1519. return error(-1, '参数错误');
  1520. }
  1521. $site->weid = $_W['weid'];
  1522. $site->uniacid = $_W['uniacid'];
  1523. $site->inMobile = true;
  1524. $method = 'doPagePayResult';
  1525. if (method_exists($site, $method)) {
  1526. $ret = array();
  1527. $ret['result'] = 'success';
  1528. $ret['type'] = $paylog['type'];
  1529. $ret['from'] = 'notify';
  1530. $ret['tid'] = $paylog['tid'];
  1531. $ret['user'] = $paylog['openid'];
  1532. $ret['fee'] = $paylog['fee'];
  1533. $ret['weid'] = $paylog['weid'];
  1534. $ret['uniacid'] = $paylog['uniacid'];
  1535. $ret['acid'] = $paylog['acid'];
  1536. $ret['is_usecard'] = $paylog['is_usecard'];
  1537. $ret['card_type'] = $paylog['card_type'];
  1538. $ret['card_fee'] = $paylog['card_fee'];
  1539. $ret['card_id'] = $paylog['card_id'];
  1540. $site->$method($ret);
  1541. }
  1542. }
  1543. }
  1544. }
  1545. abstract class WeModuleAliapp extends WeBase {
  1546. public $appid;
  1547. public $version;
  1548. public function __call($name, $arguments) {
  1549. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/aliapp';
  1550. $function_name = strtolower(substr($name, 6));
  1551. $func_file = "{$function_name}.inc.php";
  1552. $file = "$dir/{$this->version}/{$function_name}.inc.php";
  1553. if (!file_exists($file)) {
  1554. $version_path_tree = glob("$dir/*");
  1555. usort($version_path_tree, function($version1, $version2) {
  1556. return -version_compare($version1, $version2);
  1557. });
  1558. if (!empty($version_path_tree)) {
  1559. $dirs = array_filter($version_path_tree, function($path) use ($func_file){
  1560. $file_path = "$path/$func_file";
  1561. return is_dir($path) && file_exists($file_path);
  1562. });
  1563. $dirs = array_values($dirs);
  1564. $files = array_filter($version_path_tree, function($path) use ($func_file){
  1565. return is_file($path) && pathinfo($path, PATHINFO_BASENAME) == $func_file;
  1566. });
  1567. $files = array_values($files);
  1568. if (count($dirs) > 0) {
  1569. $file = current($dirs).'/'.$func_file;
  1570. } else if(count($files) > 0){
  1571. $file = current($files);
  1572. }
  1573. }
  1574. }
  1575. if(file_exists($file)) {
  1576. require $file;
  1577. exit;
  1578. }
  1579. return null;
  1580. }
  1581. public function result($errno, $message, $data = '') {
  1582. exit(json_encode(array(
  1583. 'errno' => $errno,
  1584. 'message' => $message,
  1585. 'data' => $data,
  1586. )));
  1587. }
  1588. }
  1589. abstract class WeModuleBaiduapp extends WeBase {
  1590. public $appid;
  1591. public $version;
  1592. public function __call($name, $arguments) {
  1593. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/baiduapp';
  1594. $function_name = strtolower(substr($name, 6));
  1595. $func_file = "{$function_name}.inc.php";
  1596. $file = "$dir/{$this->version}/{$function_name}.inc.php";
  1597. if (!file_exists($file)) {
  1598. $version_path_tree = glob("$dir/*");
  1599. usort($version_path_tree, function($version1, $version2) {
  1600. return -version_compare($version1, $version2);
  1601. });
  1602. if (!empty($version_path_tree)) {
  1603. $dirs = array_filter($version_path_tree, function($path) use ($func_file){
  1604. $file_path = "$path/$func_file";
  1605. return is_dir($path) && file_exists($file_path);
  1606. });
  1607. $dirs = array_values($dirs);
  1608. $files = array_filter($version_path_tree, function($path) use ($func_file){
  1609. return is_file($path) && pathinfo($path, PATHINFO_BASENAME) == $func_file;
  1610. });
  1611. $files = array_values($files);
  1612. if (count($dirs) > 0) {
  1613. $file = current($dirs).'/'.$func_file;
  1614. } else if(count($files) > 0){
  1615. $file = current($files);
  1616. }
  1617. }
  1618. }
  1619. if(file_exists($file)) {
  1620. require $file;
  1621. exit;
  1622. }
  1623. return null;
  1624. }
  1625. public function result($errno, $message, $data = '') {
  1626. exit(json_encode(array(
  1627. 'errno' => $errno,
  1628. 'message' => $message,
  1629. 'data' => $data,
  1630. )));
  1631. }
  1632. }
  1633. abstract class WeModuleToutiaoapp extends WeBase {
  1634. public $appid;
  1635. public $version;
  1636. public function __call($name, $arguments) {
  1637. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/toutiaoapp';
  1638. $function_name = strtolower(substr($name, 6));
  1639. $func_file = "{$function_name}.inc.php";
  1640. $file = "$dir/{$this->version}/{$function_name}.inc.php";
  1641. if (!file_exists($file)) {
  1642. $version_path_tree = glob("$dir/*");
  1643. usort($version_path_tree, function($version1, $version2) {
  1644. return -version_compare($version1, $version2);
  1645. });
  1646. if (!empty($version_path_tree)) {
  1647. $dirs = array_filter($version_path_tree, function($path) use ($func_file){
  1648. $file_path = "$path/$func_file";
  1649. return is_dir($path) && file_exists($file_path);
  1650. });
  1651. $dirs = array_values($dirs);
  1652. $files = array_filter($version_path_tree, function($path) use ($func_file){
  1653. return is_file($path) && pathinfo($path, PATHINFO_BASENAME) == $func_file;
  1654. });
  1655. $files = array_values($files);
  1656. if (count($dirs) > 0) {
  1657. $file = current($dirs).'/'.$func_file;
  1658. } else if(count($files) > 0){
  1659. $file = current($files);
  1660. }
  1661. }
  1662. }
  1663. if(file_exists($file)) {
  1664. require $file;
  1665. exit;
  1666. }
  1667. return null;
  1668. }
  1669. public function result($errno, $message, $data = '') {
  1670. exit(json_encode(array(
  1671. 'errno' => $errno,
  1672. 'message' => $message,
  1673. 'data' => $data,
  1674. )));
  1675. }
  1676. }
  1677. abstract class WeModuleHook extends WeBase {
  1678. }
  1679. abstract class WeModuleWebapp extends WeBase {
  1680. public function __call($name, $arguments) {
  1681. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/webapp';
  1682. $function_name = strtolower(substr($name, 6));
  1683. $file = "$dir/{$function_name}.inc.php";
  1684. if(file_exists($file)) {
  1685. require $file;
  1686. exit;
  1687. }
  1688. return null;
  1689. }
  1690. }
  1691. abstract class WeModulePhoneapp extends webase {
  1692. public $version;
  1693. public function __call($name, $arguments) {
  1694. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/phoneapp';
  1695. $function_name = strtolower(substr($name, 6));
  1696. $func_file = "{$function_name}.inc.php";
  1697. $file = "$dir/{$this->version}/{$function_name}.inc.php";
  1698. if (!file_exists($file)) {
  1699. $version_path_tree = glob("$dir/*");
  1700. usort($version_path_tree, function($version1, $version2) {
  1701. return -version_compare($version1, $version2);
  1702. });
  1703. if (!empty($version_path_tree)) {
  1704. $dirs = array_filter($version_path_tree, function($path) use ($func_file){
  1705. $file_path = "$path/$func_file";
  1706. return is_dir($path) && file_exists($file_path);
  1707. });
  1708. $dirs = array_values($dirs);
  1709. $files = array_filter($version_path_tree, function($path) use ($func_file){
  1710. return is_file($path) && pathinfo($path, PATHINFO_BASENAME) == $func_file;
  1711. });
  1712. $files = array_values($files);
  1713. if (count($dirs) > 0) {
  1714. $file = $dirs[0].'/'.$func_file;
  1715. } else if(count($files) > 0){
  1716. $file = $files[0];
  1717. }
  1718. }
  1719. }
  1720. if (file_exists($file)) {
  1721. require $file;
  1722. exit;
  1723. }
  1724. return null;
  1725. }
  1726. public function result($errno, $message, $data = '') {
  1727. exit(json_encode(array(
  1728. 'errno' => $errno,
  1729. 'message' => $message,
  1730. 'data' => $data,
  1731. )));
  1732. }
  1733. }
  1734. abstract class WeModuleSystemWelcome extends WeBase {
  1735. }
  1736. abstract class WeModuleMobile extends WeBase {
  1737. public function __call($name, $arguments) {
  1738. $dir = IA_ROOT . '/addons/' . $this->modulename . '/inc/systemWelcome';
  1739. $function_name = strtolower(substr($name, 5));
  1740. $file = "$dir/{$function_name}.inc.php";
  1741. if(file_exists($file)) {
  1742. require $file;
  1743. exit;
  1744. }
  1745. return null;
  1746. }
  1747. }