人人商城

account.class.php 54KB

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