UserController.php 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554
  1. <?php
  2. /**
  3. * Description of M
  4. *
  5. * @author zongheng
  6. */
  7. class UserController extends DooController {
  8. private $cashlimit = 100; // 充值金额奖励底限
  9. private $perlimit = 0.05; // 奖励百分比
  10. private $salelimit = 0.2; // 销售人员提成
  11. public $data;
  12. private $theme = null;
  13. public $errorMsg; //错误信息
  14. public $QArray = array(1 => '您父亲的名字是?', 2 => '您母亲的名字是?', 3 => '您的英文名字是?', 4 => '您身份证最后6位数字是?', 5 => '您就读的第一所学校全称是?');
  15. function __construct() {
  16. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  17. $this->data['rootUrl_JS'] = Doo::conf()->APP_JS_URL;
  18. $this->data['rootUrl_IMG'] = Doo::conf()->APP_IMG_URL;
  19. $this->data['rootUrl_CSS'] = Doo::conf()->APP_CSS_URL;
  20. $this->theme = Doo::conf()->APP_THEME;
  21. }
  22. /**
  23. * 管理登入
  24. */
  25. function login() {
  26. $forward = isset($this->params['forward']) ? $this->params['forward'] : 'profile';
  27. $session = Doo::session("sso");
  28. if ($session->user['id']) {
  29. if ($forward == 'deposit') {
  30. return Doo::conf()->APP_URL . 'msg/login';
  31. }
  32. }
  33. $this->data['messages'] = null;
  34. if (isset($_POST['zhusername']) && isset($_POST['zhuserpasswd'])) {
  35. $username = trim($_POST['zhusername']);
  36. $password = trim($_POST['zhuserpasswd']);
  37. if (!empty($username) && !empty($password)) {
  38. if ($this->checkMail($username)) {
  39. $user = Doo::db()->find('users', array(
  40. 'select' => 'id,username,userpasswd,useranswer,useremail,actstate,defquestion,userquestion,regdate,salt,intime,mobile',
  41. 'where' => 'useremail=?',
  42. 'param' => array($username),
  43. )
  44. );
  45. }elseif($this->checkMobile($username)){
  46. $user = Doo::db()->find('users', array(
  47. 'select' => 'id,username,userpasswd,useranswer,useremail,actstate,defquestion,userquestion,regdate,salt,intime,mobile',
  48. 'where' => 'mobile=?',
  49. 'param' => array($username),
  50. )
  51. );
  52. } else {
  53. $user = Doo::db()->find('users', array(
  54. 'select' => 'id,username,userpasswd,useranswer,salt,actstate,defquestion,userquestion,regdate,useremail,intime,mobile',
  55. 'where' => 'username=?',
  56. 'param' => array($username),
  57. )
  58. );
  59. }
  60. Doo::loadModel('userswitch');
  61. $userswitch = new UserSwitch();
  62. $usArray = $userswitch->getOne(array('select' => 'actime', 'where' => 'uid=?', 'param' => array($user[0]->id), 'asArray' => TRUE));
  63. if (!empty($user)) {
  64. if ($user[0]->userpasswd == $this->create_password($password, $user[0]->salt)) {
  65. $session = Doo::session("sso");
  66. unset($session->user);
  67. $session->user = array(
  68. 'id' => $user[0]->id,
  69. 'username' => $user[0]->username,
  70. 'password' => $user[0]->userpasswd,
  71. 'answer' => $user[0]->useranswer,
  72. 'regdate' => $user[0]->regdate,
  73. 'email' => $user[0]->useremail,
  74. 'mobile' => $user[0]->mobile,
  75. 'salt' => $user[0]->salt,
  76. 'status' => $usArray['actime'],
  77. 'defquestion' => $user[0]->defquestion,
  78. 'userquestion' => $user[0]->userquestion,
  79. );
  80. setcookie(Doo::conf()->COOKIEPRE . 'auth', $this->authcode($user[0]->id . "\t" . $this->clientIP(), 'ENCODE'), 0, '/', Doo::conf()->APP_URL, 0);
  81. setcookie(Doo::conf()->COOKIEPRE . '_userid', $this->authcode($user[0]->id, 'ENCODE'), 0, '/', Doo::conf()->APP_URL, 0);
  82. setcookie(Doo::conf()->COOKIEPRE . '_username', $this->authcode($user[0]->username, 'ENCODE'), 0, '/', Doo::conf()->APP_URL, 0);
  83. if (empty($user[0]->userquestion) && empty($user[0]->mobile))
  84. return Doo::conf()->APP_URL . 'safe';
  85. if ($forward == 'deposit') {
  86. return Doo::conf()->APP_URL . 'msg/login';
  87. }
  88. // else {
  89. // return Doo::conf()->APP_URL . 'profile';
  90. // }
  91. } else {
  92. $this->data['messages'] = '账号或者密码错误';
  93. }
  94. } else {
  95. $this->data['messages'] = '无此用户';
  96. }
  97. }
  98. }
  99. $this->data['userid'] = $session->user['id'];
  100. $this->data['username'] = $session->user['username'];
  101. $this->render($this->theme.'login', $this->data,true);
  102. }
  103. // 账户名称检测只能由中文、大小写字母、数字组成
  104. private function checkUserName($username){
  105. if (preg_match('/^[A-Za-z0-9\x{4e00}-\x{9fa5}]{3,15}$/u', $username)) {
  106. return TRUE;
  107. } else {
  108. return FALSE;
  109. }
  110. }
  111. // 检测手机验证码和验证手机是否符合
  112. private function checkSmsCode($mobile,$code){
  113. $now = time();
  114. $old = $now-900;
  115. Doo::loadModel('mobilecode');
  116. $mobilecode = new mobilecode();
  117. $user = $mobilecode->find(array(
  118. 'select' => 'id',
  119. 'where' => 'mobile='.$mobile.' and code='.$code.' and time between '.$old.' and '.$now,
  120. 'desc' => 'id',
  121. 'limit' => 1,
  122. 'asArray' => true
  123. ));
  124. if ($user) {
  125. $mobilecode->mobile=$mobile;
  126. $mobilecode->delete();
  127. return TRUE;
  128. } else {
  129. return FALSE;
  130. }
  131. }
  132. function reg() {
  133. $this->data['soft']=$this->params['soft']?$this->params['soft']:false;
  134. $web=isset($_POST['web'])?$_POST['web']:2;
  135. if($web==1)
  136. if(empty($_POST['realName'])||empty($_POST['PhoneNum'])||empty($_POST['Company'])||empty($_POST['MobileNum']))
  137. $this->render($this->theme.'register', $this->data);
  138. if (!empty($_POST['zhuser']) && !empty($_POST['zhemail']) && filter_var($_POST['zhemail'], FILTER_VALIDATE_EMAIL) && !empty($_POST['zhq']) && !empty($_POST['zhanswer']) && ($_POST['zhuser'] != $_POST['zhemail'])) {
  139. if(!$this->checkUserName($_POST['zhuser'])){
  140. return Doo::conf()->APP_URL . 'error/UserName';
  141. }
  142. // if(!$this->checkMail($_POST['zhemail'])){
  143. // return Doo::conf()->APP_URL . 'error/UserEmail';
  144. // }
  145. $strSalt = $this->create_randomstr();
  146. $stractstate = sha1(substr(uniqid(rand()), 0, 6)); // 旧激活功能代码
  147. $strpasswd = $this->create_password($_POST['zhpwdrepeat'], $strSalt);
  148. $nowtime = time();
  149. $items = array(
  150. 'username' => $_POST['zhuser'],
  151. 'useremail' => $_POST['zhemail'],
  152. 'mobile' => '',
  153. 'userpasswd' => $strpasswd,
  154. 'salt' => $strSalt,
  155. 'regip' => $this->clientIP(),
  156. 'userquestion' => htmlspecialchars($_POST['zhq']),
  157. 'defquestion' => addslashes(htmlspecialchars($_POST['defq'])),
  158. 'useranswer' => addslashes(htmlspecialchars($_POST['zhanswer'])),
  159. 'actstate' => $stractstate, // 旧激活功能代码
  160. 'intime' => $nowtime,
  161. 'regdate' => $nowtime,
  162. );
  163. doo::loadModel('users');
  164. $users = new Users();
  165. $RetValue = $users->_insertAttributes('users', $items);
  166. //插入网络版信息
  167. doo::loadModel('scUser');
  168. $scuser = new scUser();
  169. $scuser->uid=$RetValue;
  170. $scuser->Name=$_POST['realName'];
  171. $scuser->MobileNum=$_POST['MobileNum'];
  172. $scuser->Company=$_POST['Company'];
  173. $scuser->PhoneNum=$_POST['AreaCode'].'-'.$_POST['PhoneNum'];
  174. $scuser->QQ=$_POST['QQ'];
  175. $scuser->Province=$_POST['Province'];
  176. $scuser->Address=$_POST['Address'];
  177. $scuser->KnowFrom=$_POST['KnowFrom'];
  178. if($_POST['KnowFrom']==9)
  179. $scuser->KnowOther='其他';
  180. $scuser->insert();
  181. // 新注册用户加入待激活列表
  182. $rndcode = $this->create_randomstr();
  183. $acode = md5($RetValue . $rndcode);
  184. Doo::loadModel('userswitch');
  185. $UserSwitch = new UserSwitch();
  186. $UserSwitch->userAdd($RetValue, $acode, $rndcode);
  187. // End
  188. if ($RetValue) {
  189. $session = Doo::session("sso");
  190. unset($session->user);
  191. $session->user = array(
  192. 'id' => $RetValue,
  193. 'username' => $_POST['zhuser'],
  194. 'password' => $strpasswd,
  195. 'answer' => $_POST['zhanswer'],
  196. 'email' => $_POST['zhemail'],
  197. 'salt' => $strSalt,
  198. 'status' => $stractstate,
  199. 'defquestion' => addslashes(htmlspecialchars($_POST['defq'])),
  200. 'userquestion' => addslashes(htmlspecialchars($_POST['zhq'])),
  201. 'regdate' => $nowtime,
  202. );
  203. }
  204. $StrSubject = '纵横通行帐号-请激活您的帐号';
  205. $StrContent = '<table style="width:100%">
  206. <tbody>
  207. <tr><td>
  208. <p>感谢您注册成为纵横通行帐号的会员。在使用我们提供的服务之前,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以激活您的帐户:</p>
  209. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'actuser/' . $acode . '">' . Doo::conf()->APP_URL . 'actuser/' . $acode . '</a></p>
  210. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  211. <p><br>纵横通行帐号与你共成长!</p>
  212. <p>' . date('Y年m月d日', time()) . '</p>
  213. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  214. </td></tr>
  215. </tbody>
  216. </table>';
  217. @$this->SMail($_POST['zhemail'], $StrSubject, $StrContent);
  218. return Doo::conf()->APP_URL . 'sec';
  219. }
  220. $this->render($this->theme.'register', $this->data);
  221. }
  222. function smsreg(){
  223. $this->data['soft']=$this->params['soft']?$this->params['soft']:false;
  224. $web=isset($_POST['web'])?$_POST['web']:2;
  225. if($web==1)
  226. if(empty($_POST['realName'])||empty($_POST['PhoneNum'])||empty($_POST['Company'])||empty($_POST['MobileNum']))
  227. $this->render($this->theme.'register', $this->data);
  228. if (!empty($_POST['zhmuser']) && !empty($_POST['zhmobile']) && !empty($_POST['zhsmscode']) && !empty($_POST['zhmpasswd'])) {
  229. if(!$this->checkUserName($_POST['zhmuser'])){
  230. return Doo::conf()->APP_URL . 'error/UserName';
  231. }
  232. if(!$this->checkSmsCode($_POST['zhmobile'],$_POST['zhsmscode'])){
  233. return Doo::conf()->APP_URL . 'error/mobile';
  234. }
  235. $strSalt = $this->create_randomstr();
  236. $stractstate = sha1(substr(uniqid(rand()), 0, 6)); // 旧激活功能代码
  237. $strpasswd = $this->create_password($_POST['zhmpasswd'], $strSalt);
  238. $nowtime = time();
  239. $items = array(
  240. 'username' => $_POST['zhmuser'],
  241. 'mobile' => $_POST['zhmobile'],
  242. 'useremail' => '',
  243. 'userpasswd' => '',
  244. 'userquestion' => '',
  245. 'useranswer' => '',
  246. 'userpasswd' => $strpasswd,
  247. 'salt' => $strSalt,
  248. 'regip' => $this->clientIP(),
  249. 'actstate' => $stractstate, // 旧激活功能代码
  250. 'intime' => $nowtime,
  251. 'regdate' => $nowtime,
  252. );
  253. doo::loadModel('users');
  254. $users = new Users();
  255. $RetValue = $users->_insertAttributes('users', $items);
  256. //插入网络版信息
  257. doo::loadModel('scUser');
  258. $scuser = new scUser();
  259. $scuser->uid=$RetValue;
  260. // $scuser->Name=$_POST['realName'];
  261. // $scuser->MobileNum=$_POST['MobileNum'];
  262. // $scuser->Company=$_POST['Company'];
  263. // $scuser->PhoneNum=$_POST['AreaCode'].'-'.$_POST['PhoneNum'];
  264. // $scuser->QQ=$_POST['QQ'];
  265. // $scuser->Province=$_POST['Province'];
  266. // $scuser->Address=$_POST['Address'];
  267. // $scuser->KnowFrom=$_POST['KnowFrom'];
  268. // if($_POST['KnowFrom']==9)
  269. // $scuser->KnowOther='其他';
  270. $scuser->insert();
  271. if ($RetValue) {
  272. $session = Doo::session("sso");
  273. unset($session->user);
  274. $session->user = array(
  275. 'id' => $RetValue,
  276. 'username' => $_POST['zhmuser'],
  277. 'password' => $strpasswd,
  278. 'answer' => '',
  279. 'email' => '',
  280. 'mobile' => $_POST['zhmobile'],
  281. 'salt' => $strSalt,
  282. 'status' => $stractstate,
  283. 'defquestion' => '',
  284. 'userquestion' => '',
  285. 'regdate' => $nowtime,
  286. );
  287. }
  288. $this->data['username'] = $_POST['zhmuser'];
  289. $this->data['mobile'] = $_POST['zhmobile'];
  290. if(isset($_POST['mobilereg'])){
  291. $this->render($this->theme.'registerMobile-success', $this->data);
  292. }else{
  293. $this->render($this->theme.'successM', $this->data);
  294. }
  295. die();
  296. }else{
  297. if(isset($_POST['mobilereg'])) {
  298. $this->render($this->theme.'registerMobile', $this->data);
  299. }else{
  300. $this->render($this->theme.'register', $this->data);
  301. }
  302. }
  303. }
  304. /**
  305. * 生成随机字符串
  306. * @param string $lenth 长度
  307. * @return string 字符串
  308. */
  309. function create_randomstr($lenth = 6) {
  310. return $this->random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
  311. }
  312. /**
  313. *
  314. * @param $password 密码
  315. * @param $random 随机数
  316. */
  317. function create_password($password = '', $random = '') {
  318. if (empty($random)) {
  319. $array['random'] = $this->create_randomstr();
  320. $array['password'] = md5(md5($password) . $array['random']);
  321. return $array;
  322. }
  323. return md5(md5($password) . $random);
  324. }
  325. /**
  326. * 随机字符串函数
  327. * @param $password 密码
  328. * @param $random 随机数
  329. */
  330. function random($length, $chars = '0123456789') {
  331. $hash = '';
  332. $max = strlen($chars) - 1;
  333. for ($i = 0; $i < $length; $i++) {
  334. $hash .= $chars[mt_rand(0, $max)];
  335. }
  336. return $hash;
  337. }
  338. function setpasswd() {
  339. $session = Doo::session("sso");
  340. if (empty($session->user['id'])) {
  341. return Doo::conf()->APP_URL . 'error/loginFail';
  342. }
  343. $StrEncode = $this->authcode(base64_decode($this->params['AuthStr']), 'DECODE');
  344. if (empty($StrEncode))
  345. exit('error');
  346. list($userid, $useremail, $timetemp) = explode('|', $StrEncode);
  347. if ((time() - $timetemp) > 86400) {
  348. exit('error');
  349. }
  350. $user = Doo::db()->find('users', array(
  351. 'select' => 'id,salt',
  352. 'where' => 'useremail=?',
  353. 'param' => array($useremail),
  354. )
  355. );
  356. if (empty($user)) {
  357. exit('error');
  358. }
  359. if ($userid != $user[0]->id) {
  360. exit('error!');
  361. }
  362. $this->data['messages'] = null;
  363. if (!empty($_POST['answer']) && !empty($_POST['newpasswd']) && !empty($_POST['repeatnew']) && ($_POST['newpasswd'] == $_POST['repeatnew'])) {
  364. $useranswer = htmlspecialchars($_POST['answer']);
  365. $userrepeatnew = $_POST['repeatnew'];
  366. Doo::loadModel('users');
  367. $objuser = new Users();
  368. $objuser->userpasswd = $this->create_password($userrepeatnew, $user[0]->salt);
  369. $RetValue = $objuser->update(array('where' => 'id=' . $userid . ' AND useremail=\'' . $useremail . '\' AND useranswer=\'' . $useranswer . '\''));
  370. if ($RetValue)
  371. $this->data['messages'] = '密码重置成功';
  372. return Doo::conf()->APP_URL;
  373. }
  374. $this->data['defquestion'] = null;
  375. $session = Doo::session("sso");
  376. if (!empty($session->user['defquestion']) || ($session->user['userquestion'] == 6))
  377. $this->data['defquestion'] = htmlspecialchars_decode($session->user['defquestion']);
  378. if (!empty($session->user['userquestion']) && ($session->user['userquestion'] != 6))
  379. $this->data['defquestion'] = $this->QArray[$session->user['userquestion']];
  380. $this->data['StrAuth'] = $this->params['AuthStr'];
  381. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  382. $this->render($this->theme.'getPassword2', $this->data);
  383. }
  384. function getpasswd() {
  385. // $flash = new DooFlashMessenger();
  386. // $flash->addMessage("This is just test message");
  387. // $this->data['messages'] = $flash->displayMessages();
  388. $gpemail = isset($_POST['email']) ? $_POST['email'] : NULL;
  389. if (!empty($gpemail) && isset($_POST['emailsubmit'])) {
  390. if ($this->checkMail($gpemail)) {
  391. $user = Doo::db()->find('users', array(
  392. 'select' => 'id,salt,username,useremail',
  393. 'where' => 'useremail=?',
  394. 'param' => array($gpemail),
  395. )
  396. );
  397. } else {
  398. $user = Doo::db()->find('users', array(
  399. 'select' => 'id,salt,username,useremail',
  400. 'where' => 'username=?',
  401. 'param' => array($gpemail)
  402. )
  403. );
  404. }
  405. if (!empty($user)) {
  406. // TODO:重新设置密码过程
  407. $newPasswdStr = $this->create_randomstr();
  408. $newPasswd = $this->create_password($newPasswdStr, $user[0]->salt);
  409. $usersObj = Doo::loadModel('users', TRUE);
  410. $usersObj->id = $user[0]->id;
  411. $usersObj->userpasswd = $newPasswd;
  412. if ($usersObj->update()) {
  413. $StrSubject = '纵横通行帐号提醒您:您的帐号修改了新密码';
  414. $StrContent = '<table style="width:100%">
  415. <tbody>
  416. <tr><td>
  417. <p>尊敬的' . $user[0]->username . ':</p>
  418. <p><br>您的通行帐号修改了新的密码(区分大小写):<b style="font-size:18px">' . $newPasswdStr . '</b></p>
  419. <p><br>请妥善保管您的新密码,及时登陆纵横通行证进行更新。</p>
  420. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  421. <p><br>纵横通行帐号与你共成长!</p>
  422. <p>' . date('Y年m月d日', time()) . '</p>
  423. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  424. </td></tr>
  425. </tbody>
  426. </table>';
  427. if ($this->SMail($user[0]->useremail, $StrSubject, $StrContent)) {
  428. $this->data['messages'] = '密码找回完成,请查收您的邮箱';
  429. header('refresh:2;url=' . Doo::conf()->APP_URL);
  430. $this->render($this->theme.'getPConfirm', $this->data, TRUE);
  431. exit();
  432. }
  433. }
  434. } else {
  435. $this->data['messages'] = '账号或邮箱有误,请重新输入';
  436. }
  437. }
  438. if(isset($_POST['mobilesubmit'])){
  439. if($this->checkSmsCode($_POST['zhmobile'],$_POST['zhsmscode'])){
  440. $user = Doo::db()->find('users', array(
  441. 'select' => 'id,salt,username,mobile',
  442. 'where' => 'mobile=?',
  443. 'param' => array($_POST['zhmobile'])
  444. )
  445. );
  446. if(!empty($user)){
  447. // TODO:重新设置密码过程
  448. $newPasswdStr = $_POST['password'];
  449. $newPasswd = $this->create_password($newPasswdStr, $user[0]->salt);
  450. $usersObj = Doo::loadModel('users', TRUE);
  451. $usersObj->id = $user[0]->id;
  452. $usersObj->userpasswd = $newPasswd;
  453. if ($usersObj->update()) {
  454. return Doo::conf()->APP_URL . 'notic/repwdmobile';
  455. exit();
  456. }else{
  457. $this->data['messages2'] = '新密码有误,请重新输入';
  458. }
  459. } else {
  460. $this->data['messages2'] = '手机号有误,请重新输入';
  461. }
  462. }else{
  463. $this->data['messages2'] = '验证码过期或不一致,请重新获取';
  464. }
  465. }
  466. $this->data['messages'] = isset($this->data['messages']) ? $this->data['messages'] : NULL;
  467. $this->data['messages2'] = isset($this->data['messages2']) ? $this->data['messages2'] : NULL;
  468. $this->render($this->theme.'getPassword', $this->data);
  469. }
  470. function ActEmail() {
  471. $session = Doo::session("sso");
  472. if (empty($session->user['id'])) {
  473. return Doo::conf()->APP_URL . 'error/loginFail';
  474. }
  475. if (empty($this->params['AuthStr'])) {
  476. return Doo::conf()->APP_URL . 'error/actemail';
  477. }
  478. $StrEncode = $this->authcode(base64_decode($this->params['AuthStr']), 'DECODE');
  479. if (empty($StrEncode))
  480. return Doo::conf()->APP_URL . 'error/actemail';
  481. if (!empty($session->user['status'])) {
  482. if (empty($session->user['status'])) {
  483. $this->data['name'] = $session->user['username'];
  484. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  485. $this->render($this->theme.'success', $this->data);
  486. exit();
  487. }
  488. list($userid, $userstatus, $uemail, $timetemp) = explode('|', $StrEncode);
  489. if ($session->user['email'] != $uemail) {
  490. return Doo::conf()->APP_URL . 'error/actemail';
  491. }
  492. if ((time() - $timetemp) > 86400) {
  493. return Doo::conf()->APP_URL . 'error/actemail';
  494. }
  495. if (empty($userstatus)) {
  496. return Doo::conf()->APP_URL . 'error/actemail';
  497. }
  498. if ($userid != $session->user['id']) {
  499. return Doo::conf()->APP_URL . 'error/actemail';
  500. }
  501. Doo::loadModel('users');
  502. $objuser = new Users();
  503. $objuser->actstate = 0;
  504. $RetValue = $objuser->update(array('where' => 'id=' . $session->user['id']));
  505. if ($RetValue)
  506. $session->user['status'] = null;
  507. }
  508. $this->data['name'] = $session->user['username'];
  509. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  510. $this->render($this->theme.'success', $this->data);
  511. }
  512. function activeUserDo() {
  513. $accode = $this->params['AuthStr'];
  514. if (empty($accode)) {
  515. return Doo::conf()->APP_URL . 'error/actUserError';
  516. }
  517. // 检测账号激活状态
  518. Doo::loadModel('userswitch');
  519. $userswitch = new UserSwitch();
  520. $usArray = $userswitch->getOne(array('where' => 'actcode=?', 'param' => array($accode), 'asArray' => TRUE));
  521. // $checkActCode = md5($usArray['uid'] . $usArray['rndcode']);
  522. if (!empty($usArray)) {
  523. if (!self::isUserActive($usArray['uid'])) {
  524. $userswitch->actime = time();
  525. $userswitch->update(array('where' => 'uid=?', 'param' => array($usArray['uid'])));
  526. Doo::loadModel('users');
  527. $user = new Users();
  528. $name = $user->getOne(array('select' => 'username,useremail', 'where' => 'id=?', 'param' => array($usArray['uid']), 'asArray' => TRUE));
  529. } else {
  530. return Doo::conf()->APP_URL . 'error/actived';
  531. }
  532. } else {
  533. return Doo::conf()->APP_URL . 'error/actUserError';
  534. }
  535. $this->data['name'] = $name['username'];
  536. $this->data['email'] = $name['useremail'];
  537. $this->render($this->theme.'success', $this->data);
  538. }
  539. function CheckNewEMail() {
  540. // ini_set('display_errors', on);
  541. $session = Doo::session("sso");
  542. if (empty($session->user['id'])) {
  543. return Doo::conf()->APP_URL . 'error/loginFail';
  544. }
  545. if (empty($session->user['userquestion'])) {
  546. return Doo::conf()->APP_URL . 'safe';
  547. }
  548. $password = isset($_POST['password']) ? $_POST['password'] : NULL;
  549. $email = isset($_POST['email']) ? $_POST['email'] : NULL;
  550. if (!empty($email) && !empty($password) && $this->checkMail($email)) {
  551. if ($session->user['email'] == $_POST['email']) {
  552. $this->data['message'] = '邮箱已被注册';
  553. } else {
  554. if (!$this->checkExsitmail($email)) {
  555. $this->data['message'] = '请尝试其他邮箱';
  556. exit;
  557. }
  558. if ($session->user['password'] != $this->create_password($_POST['password'], $session->user['salt'])) {
  559. $this->data['message'] = '请重新确认您输入的密码';
  560. exit;
  561. }
  562. if ($this->sendmail($session->user['id'] . '|' . $_POST['email'] . '|' . time(), $_POST['email'])) {
  563. $this->data['email'] = $_POST['email'];
  564. $this->render($this->theme.'changeMail2', $this->data, TRUE);
  565. die();
  566. } else {
  567. $this->data['message'] = '发送失败,请联系管理员~';
  568. }
  569. }
  570. }
  571. $this->data['message'] = isset($this->data['message']) ? $this->data['message'] : NULL;
  572. $this->data['email'] = $session->user['email'];
  573. $this->data['name'] = $session->user['username'];
  574. $this->render($this->theme.'changeMail', $this->data, TRUE);
  575. }
  576. function CheckNewMobile() {
  577. // ini_set('display_errors', on);
  578. $session = Doo::session("sso");
  579. if (empty($session->user['id'])) {
  580. return Doo::conf()->APP_URL . 'error/loginFail';
  581. }
  582. $password = isset($_POST['password']) ? $_POST['password'] : NULL;
  583. $mobile = isset($_POST['zhmobile']) ? $_POST['zhmobile'] : NULL;
  584. $code = isset($_POST['zhsmscode']) ? $_POST['zhsmscode'] : NULL;
  585. if (!empty($mobile) && !empty($password) && !empty($code) && $this->checkMobile($mobile)) {
  586. if ($session->user['mobile'] == $_POST['zhmobile']) {
  587. $this->data['message'] = '该手机号码已被注册';
  588. return Doo::conf()->APP_URL . 'error/hadmobile';
  589. exit;
  590. } else {
  591. if (!$this->checkExsitMobile($mobile)) {
  592. $this->data['message'] = '请尝试其他手机号';
  593. return Doo::conf()->APP_URL . 'error/hadmobile';
  594. exit;
  595. }
  596. if ($session->user['password'] != $this->create_password($_POST['password'], $session->user['salt'])) {
  597. $this->data['message'] = '请重新确认您输入的密码';
  598. return Doo::conf()->APP_URL . 'error/mima';
  599. exit;
  600. }
  601. if(!$this->checkSmsCode($mobile,$code)){
  602. $this->data['message'] = '验证码过期或不一致,请重新获取';
  603. return Doo::conf()->APP_URL . 'error/mobile';
  604. exit();
  605. }
  606. Doo::loadModel('users');
  607. $objuser = new Users();
  608. $objuser->mobile = $mobile;
  609. $RetValue = $objuser->update(array('where' => 'id=' . $session->user['id']));
  610. if ($RetValue){
  611. $session->user['mobile'] = $mobile;
  612. $this->data['mobile'] = $mobile;
  613. $this->render($this->theme.'changeMobile2', $this->data, TRUE);
  614. die();
  615. }else{
  616. $this->data['message'] = '修改失败,请重试';
  617. return Doo::conf()->APP_URL . 'error';
  618. exit;
  619. }
  620. }
  621. }
  622. $this->data['message'] = isset($this->data['message']) ? $this->data['message'] : NULL;
  623. $this->data['mobile'] = $session->user['mobile'];
  624. $this->data['name'] = $session->user['username'];
  625. $this->render($this->theme.'changeMobile', $this->data, TRUE);
  626. }
  627. function AddMail(){
  628. $session = Doo::session("sso");
  629. if (empty($session->user['id'])) {
  630. return Doo::conf()->APP_URL . 'error/loginFail';
  631. }
  632. if(!empty($_POST['email']) && !empty($_POST['password'])){
  633. if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
  634. $this->data['message'] = '邮箱格式出错';
  635. return Doo::conf()->APP_URL . 'error/erroremail';
  636. exit;
  637. }
  638. if (!$this->checkExsitmail($_POST['email'])) {
  639. $this->data['message'] = '邮箱已被注册';
  640. return Doo::conf()->APP_URL . 'error/userdemail';
  641. exit;
  642. }
  643. if ($session->user['password'] != $this->create_password($_POST['password'], $session->user['salt'])) {
  644. $this->data['message'] = '请重新确认您输入的密码';
  645. return Doo::conf()->APP_URL . 'error/mima';
  646. exit;
  647. }
  648. $userquestion = htmlspecialchars($_POST['zhq']);
  649. $defquestion = addslashes(htmlspecialchars($_POST['defq']));
  650. $useranswer = addslashes(htmlspecialchars($_POST['zhanswer']));
  651. Doo::loadModel('users');
  652. $users = new Users();
  653. $users->useremail = $_POST['email'];
  654. $users->userquestion = $userquestion;
  655. $users->defquestion = $defquestion;
  656. $users->useranswer = $useranswer;
  657. $RetValue = $users->update(array('where' => 'id=' . $session->user['id']));
  658. // 新注册用户加入待激活列表
  659. $rndcode = $this->create_randomstr();
  660. $acode = md5($session->user['id'] . $rndcode);
  661. Doo::loadModel('userswitch');
  662. $UserSwitch = new UserSwitch();
  663. $UserSwitch->userAdd($session->user['id'], $acode, $rndcode);
  664. if ($RetValue){
  665. $session->user['defquestion'] = $defquestion;
  666. $session->user['userquestion'] = $userquestion;
  667. $session->user['answer'] = $useranswer;
  668. $session->user['email'] = $_POST['email'];
  669. }
  670. $StrSubject = '纵横通行帐号-请激活您的帐号';
  671. $StrContent = '<table style="width:100%">
  672. <tbody>
  673. <tr><td>
  674. <p>感谢您注册成为纵横通行帐号的会员。在使用我们提供的服务之前,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以激活您的帐户:</p>
  675. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'actuser/' . $acode . '">' . Doo::conf()->APP_URL . 'actuser/' . $acode . '</a></p>
  676. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  677. <p><br>纵横通行帐号与你共成长!</p>
  678. <p>' . date('Y年m月d日', time()) . '</p>
  679. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  680. </td></tr>
  681. </tbody>
  682. </table>';
  683. @$this->SMail($_POST['email'], $StrSubject, $StrContent);
  684. $this->data['email'] = $_POST['email'];
  685. $this->render($this->theme.'changeMail2', $this->data, TRUE);
  686. die();
  687. }
  688. $this->data['name'] = $session->user['username'];
  689. $this->data['message'] = isset($this->data['message']) ? $this->data['message'] : NULL;
  690. $this->render($this->theme.'addMail', $this->data, TRUE);
  691. }
  692. function AddMobile(){
  693. $session = Doo::session("sso");
  694. if (empty($session->user['id'])) {
  695. return Doo::conf()->APP_URL . 'error/loginFail';
  696. }
  697. $password = isset($_POST['password']) ? $_POST['password'] : NULL;
  698. $mobile = isset($_POST['zhmobile']) ? $_POST['zhmobile'] : NULL;
  699. $code = isset($_POST['zhsmscode']) ? $_POST['zhsmscode'] : NULL;
  700. if (!empty($mobile) && !empty($password) && !empty($code) && $this->checkMobile($mobile)) {
  701. if ($session->user['mobile'] == $_POST['zhmobile']) {
  702. $this->data['message'] = '该手机号码已被注册';
  703. return Doo::conf()->APP_URL . 'error/hadmobile';
  704. exit;
  705. } else {
  706. if (!$this->checkExsitMobile($mobile)) {
  707. $this->data['message'] = '请尝试其他手机号';
  708. return Doo::conf()->APP_URL . 'error/hadmobile';
  709. exit;
  710. }
  711. if ($session->user['password'] != $this->create_password($_POST['password'], $session->user['salt'])) {
  712. $this->data['message'] = '请重新确认您输入的密码';
  713. return Doo::conf()->APP_URL . 'error/mima';
  714. exit;
  715. }
  716. if(!$this->checkSmsCode($mobile,$code)){
  717. $this->data['message'] = '验证码过期或不一致,请重新获取';
  718. return Doo::conf()->APP_URL . 'error/mobile';
  719. exit();
  720. }
  721. Doo::loadModel('users');
  722. $objuser = new Users();
  723. $objuser->mobile = $mobile;
  724. $RetValue = $objuser->update(array('where' => 'id=' . $session->user['id']));
  725. if ($RetValue){
  726. $session->user['mobile'] = $mobile;
  727. // $this->data['mobile'] = $mobile;
  728. return Doo::conf()->APP_URL . 'notic/addmobile';
  729. // $this->render($this->theme.'addMobile2', $this->data, TRUE);
  730. die();
  731. }else{
  732. $this->data['message'] = '修改失败,请重试';
  733. return Doo::conf()->APP_URL . 'error';
  734. exit;
  735. }
  736. }
  737. }
  738. $this->data['name'] = $session->user['username'];
  739. $this->data['message'] = isset($this->data['message']) ? $this->data['message'] : NULL;
  740. $this->render($this->theme.'addMobile', $this->data, TRUE);
  741. }
  742. // Email发送函数
  743. function sendmail($StrEncodeAuth, $toemail) {
  744. Doo::loadClass('class.phpmailer');
  745. $mail = new PHPMailer();
  746. $mail->From = "websupport@smartcost.com.cn"; //发送邮箱全名
  747. $mail->FromName = "=?UTF-8?B?" . base64_encode("纵横知道·通行证") . "?="; //发送人昵称
  748. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  749. $mail->Password = "cDO1GjtY1seH"; //密码
  750. $mail->CharSet = "UTF8";
  751. $mail->SMTPAuth = true;
  752. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  753. $mail->Port = 25;
  754. $mail->Mailer = "smtp";
  755. $mail->Subject = "=?UTF-8?B?" . base64_encode('纵横通行帐号-修改邮箱确认') . "?=";
  756. $tmplate = '
  757. <table style="width:100%">
  758. <tbody>
  759. <tr><td>
  760. <p>您对通行帐号进行了修改邮箱操作,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以验证您的新邮箱:</p>
  761. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'ChangEmail/' . base64_encode($this->authcode($StrEncodeAuth, 'ENCODE')) . '">' . Doo::conf()->APP_URL . 'ChangEmail/' . base64_encode($this->authcode($StrEncodeAuth, 'ENCODE')) . '</a></p>
  762. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  763. <p><br>纵横通行帐号与你共成长!</p>
  764. <p>' . date('Y年m月d日', time()) . '</p>
  765. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  766. </td></tr>
  767. </tbody>
  768. </table>';
  769. $mail->MsgHTML($tmplate);
  770. $mail->AddAddress($toemail);
  771. $mail->CharSet = "UTF-8";
  772. return $mail->Send();
  773. }
  774. // Email发送函数
  775. function SMail($toemail, $subject, $contents) {
  776. Doo::loadClass('class.phpmailer');
  777. $mail = new PHPMailer();
  778. $mail->From = "websupport@smartcost.com.cn"; //发送邮箱全名
  779. $mail->FromName = "=?UTF-8?B?" . base64_encode("纵横知道·通行证") . "?="; //发送人昵称
  780. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  781. $mail->Password = "cDO1GjtY1seH"; //密码
  782. $mail->CharSet = "UTF8";
  783. $mail->SMTPAuth = true;
  784. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  785. $mail->Mailer = "smtp";
  786. $mail->Port = 25;
  787. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  788. $mail->MsgHTML($contents);
  789. $mail->AddAddress($toemail);
  790. $mail->CharSet = "UTF-8";
  791. return $mail->Send();
  792. }
  793. // 变更邮箱第二步
  794. function ChangEmail() {
  795. $session = Doo::session("sso");
  796. if (empty($session->user['id'])) {
  797. return Doo::conf()->APP_URL . 'error/loginFail';
  798. }
  799. if (empty($session->user['userquestion'])) {
  800. return Doo::conf()->APP_URL . 'safe';
  801. }
  802. $StrEncode = $this->authcode(base64_decode($this->params['AuthStr']), 'DECODE');
  803. if (empty($StrEncode))
  804. return Doo::conf()->APP_URL . 'error/actemail';
  805. list($userid, $useremail, $timetemp) = explode('|', $StrEncode);
  806. if ((time() - $timetemp) > 86400) {
  807. return Doo::conf()->APP_URL . 'error/actemail';
  808. }
  809. if (!$this->checkMail($useremail)) {
  810. return Doo::conf()->APP_URL . 'error/actemail';
  811. }
  812. if ($userid != $session->user['id']) {
  813. return Doo::conf()->APP_URL . 'error/actemail';
  814. }
  815. if ($useremail == $session->user['email']) {
  816. return Doo::conf()->APP_URL . 'error/actemail';
  817. }
  818. Doo::loadModel('users');
  819. $objuser = new Users();
  820. $objuser->useremail = $useremail;
  821. $RetValue = $objuser->update(array('where' => 'id=' . $session->user['id']));
  822. if ($RetValue)
  823. $session->user['email'] = $useremail;
  824. $this->data['email'] = $useremail;
  825. $this->render($this->theme.'changeMail3', $this->data);
  826. }
  827. function secmail() {
  828. // TODO:切换新邮箱未发送此激活邮箱的激活邮件
  829. // TODO:检测已存在邮箱与
  830. $session = Doo::session("sso");
  831. if ($session->user['status'] == 0) {
  832. return Doo::conf()->APP_URL;
  833. }
  834. if (!empty($_POST['sendsubmit'])) {
  835. $StrSubject = '纵横通行帐号-修改邮箱确认';
  836. $StrContent = '<table style="width:100%">
  837. <tbody>
  838. <tr>
  839. <td>
  840. <p>您对通行帐号进行了修改邮箱操作,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以验证您的新邮箱:</p>
  841. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'ActEmail/' . base64_encode($this->authcode($session->user['id'] . '|' . $session->user['status'] . '|' . $session->user['email'] . '|' . time(), 'ENCODE')) . '">' . Doo::conf()->APP_URL . 'ActEmail/' . base64_encode($this->authcode($session->user['id'] . '|' . $session->user['status'] . '|' . $session->user['email'] . '|' . time(), 'ENCODE')) . '</a></p>
  842. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  843. <p><br>纵横通行帐号与你共成长!</p>
  844. <p>' . date('Y年m月d日', time()) . '</p>
  845. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  846. </td>
  847. </tr>
  848. </tbody>
  849. </table>';
  850. $this->SMail($session->user['email'], $StrSubject, $StrContent);
  851. // return Doo::conf()->APP_URL . 'sec';
  852. }
  853. if (!empty($_POST['email']))
  854. if ($this->checkMail($_POST['email']) && !empty($_POST['email']) && ($_POST['email'] != $session->user['email'])) {
  855. Doo::loadModel('users');
  856. $objuser = new Users();
  857. $objuser->useremail = $_POST['email'];
  858. $RetValue = $objuser->update(array('where' => 'id=' . $session->user['id']));
  859. if ($RetValue)
  860. $session->user['email'] = $_POST['email'];
  861. $StrSubject = '纵横通行帐号-修改邮箱确认';
  862. $StrContent = '<table style="width:100%">
  863. <tbody>
  864. <tr>
  865. <td>
  866. <p>您对通行帐号进行了修改邮箱操作,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以验证您的新邮箱:</p>
  867. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'ActEmail/' . base64_encode($this->authcode($session->user['id'] . '|' . $session->user['status'] . '|' . $session->user['email'] . '|' . time(), 'ENCODE')) . '">' . Doo::conf()->APP_URL . 'ActEmail/' . base64_encode($this->authcode($session->user['id'] . '|' . $session->user['status'] . '|' . $session->user['email'] . '|' . time(), 'ENCODE')) . '</a></p>
  868. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  869. <p><br>纵横通行帐号与你共成长!</p>
  870. <p>' . date('Y年m月d日', time()) . '</p>
  871. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  872. </td>
  873. </tr>
  874. </tbody>
  875. </table>';
  876. if ($this->SMail($session->user['email'], $StrSubject, $StrContent)) {
  877. return Doo::conf()->APP_URL . 'sec';
  878. }
  879. }
  880. $this->data['email'] = isset($session->user['email']) ? $session->user['email'] : NULL;
  881. $this->render($this->theme.'register2', $this->data);
  882. }
  883. function profile() {
  884. $session = Doo::session("sso");
  885. if (!isset($session->user['id'])) {
  886. return Doo::conf()->APP_URL . 'error/loginFail';
  887. }
  888. if ($this->checkUserQuestion($session->user['id']) && (!isset($session->user['mobile']) && empty($session->user['mobile'])))
  889. return Doo::conf()->APP_URL . 'safe';
  890. if (!empty($_POST['sendsubmit'])) {
  891. if (self::isUserActive($session->user['id']))
  892. return Doo::conf()->APP_URL . 'error/actuser';
  893. Doo::loadModel('userswitch');
  894. $UserSwitch = new UserSwitch();
  895. $usArray = $UserSwitch->getOne(array('where' => 'uid=?', 'param' => array($session->user['id']), 'asArray' => TRUE));
  896. $StrSubject = '纵横通行帐号-请激活您的帐号';
  897. $StrContent = '<table style="width:100%">
  898. <tbody>
  899. <tr>
  900. <td>
  901. <p>感谢您注册成为纵横通行帐号的会员。在使用我们提供的服务之前,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以激活您的帐户:</p>
  902. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'actuser/' . $usArray['actcode'] . '">' . Doo::conf()->APP_URL . 'actuser/' . $usArray['actcode'] . '</a></p>
  903. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  904. <p><br>纵横通行帐号与你共成长!</p>
  905. <p>' . date('Y年m月d日', time()) . '</p>
  906. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  907. </td>
  908. </tr>
  909. </tbody>
  910. </table>';
  911. if ($this->SMail($session->user['email'], $StrSubject, $StrContent)) {
  912. return Doo::conf()->APP_URL . 'error/isact';
  913. }
  914. }
  915. Doo::loadModel('users');
  916. $users = new Users();
  917. $valuebank = $users->getRowByUid($session->user['id']);
  918. $this->data['bank'] = isset($valuebank[0]['bank']) ? $valuebank[0]['bank'] : 0;
  919. $this->data['name'] = $session->user['username'];
  920. // $this->data['avatar'] = $this->url_exists($this->ps_getavatar($session->user['id'])) ? $this->ps_getavatar($session->user['id']) : Doo::conf()->APP_URL . 'global/img/avatra48.png';
  921. if(isset($session->user['id'])){
  922. $this->data['avatar'] = $this->ps_getavatar($session->user['id']);
  923. }else{
  924. $this->data['avatar'] = Doo::conf()->APP_URL . 'global/img/avatra48.png';
  925. }
  926. $this->data['regdate'] = $session->user['regdate'];
  927. $this->data['email'] = $session->user['email'];
  928. $this->data['mobile'] = $session->user['mobile'];
  929. // $this->data['status'] = $session->user['status'];
  930. $this->data['status'] = self::isUserActive($session->user['id']);
  931. $this->data['FUN'] = __FUNCTION__;
  932. $this->render($this->theme.'profile', $this->data, TRUE);
  933. }
  934. private function url_exists($url) {
  935. $h = get_headers($url);
  936. if (!$h || !isset($h[0]))
  937. return false;
  938. $status = $h[0];
  939. return preg_match("/.*200\s{1}OK/i", $status) ? true : false;
  940. }
  941. function chpasswd() {
  942. // TODO:变更密码后更新SESSION中数据
  943. $session = Doo::session("sso");
  944. if (empty($session->user['id'])) {
  945. return Doo::conf()->APP_URL . 'error/loginFail';
  946. }
  947. if (empty($session->user['userquestion']) && empty($session->user['mobile'])) {
  948. return Doo::conf()->APP_URL . 'safe';
  949. }
  950. $this->data['erroT']="";
  951. $this->data['erroTxt']='';
  952. $this->data['aerroT']="";
  953. $this->data['aerroTxt']='';
  954. $this->data['defquestion'] = null;
  955. $this->data['mobile'] = !empty($session->user['mobile']) ? $session->user['mobile'] : '';
  956. $this->data['userquestion'] = !empty($session->user['userquestion']) ? $session->user['userquestion'] : '';
  957. $this->data['name'] = $session->user['username'];
  958. if (!empty($session->user['defquestion']) || ($session->user['userquestion'] == 6))
  959. $this->data['defquestion'] = $session->user['defquestion'];
  960. if (!empty($session->user['userquestion']) && ($session->user['userquestion'] != 6))
  961. $this->data['defquestion'] = $this->QArray[$session->user['userquestion']];
  962. if (!empty($_POST['subchpwd'])) {
  963. if(isset($_POST['answer']) && !empty($_POST['answer'])){
  964. if($session->user['answer'] == $_POST['answer']){
  965. $action = 1;
  966. }else{
  967. $this->data['erroT']="";
  968. $this->data['erroTxt']='';
  969. $this->data['aerroT']="erroT";
  970. $this->data['aerroTxt']='<span for="oldpwd" generated="true" class="erroT" style="">输入的答案错误</span>';
  971. $this->render($this->theme.'changePassword', $this->data);die;
  972. }
  973. }elseif(isset($_POST['zhsmscode']) && !empty($_POST['zhsmscode'])){
  974. if($this->checkSmsCode($session->user['mobile'],$_POST['zhsmscode'])){
  975. $action = 2;
  976. }else{
  977. $this->data['erroT']="";
  978. $this->data['erroTxt']='';
  979. $this->data['aerroT']="erroT";
  980. $this->data['aerroTxt']='<span for="oldpwd" generated="true" class="erroT" style="">验证码过期或不一致,请重新获取</span>';
  981. $this->render($this->theme.'changePassword', $this->data);die;
  982. }
  983. }else{
  984. $this->data['erroT']="";
  985. $this->data['erroTxt']='';
  986. $this->data['aerroT']="erroT";
  987. $this->data['aerroTxt']='<span for="oldpwd" generated="true" class="erroT" style="">请输入密保答案或手机验证码</span>';
  988. $this->render($this->theme.'changePassword', $this->data);die;
  989. }
  990. if (($session->user['password'] == $this->create_password($_POST['oldpwd'], $session->user['salt']))) {
  991. Doo::loadModel('users');
  992. $objuser = new Users();
  993. // $objuser->id = $session->user['id'];
  994. $objuser->userpasswd = $this->create_password($_POST['newpwd'], $session->user['salt']);
  995. // $objuser->useranswer = $session->user['password'];
  996. // $AryUser[] = $objuser;
  997. $objuser->update(array('where' => 'useranswer=\'' . $session->user['answer'] . '\' and id=' . $session->user['id']));
  998. if($action == 1){
  999. $StrSubject = '纵横通行帐号提醒您:您的帐号修改了新密码';
  1000. $StrContent = '<table style="width:100%">
  1001. <tbody>
  1002. <tr><td>
  1003. <p>尊敬的' . $session->user['username'] . ':</p>
  1004. <p><br>您的通行帐号修改了新的密码</p>
  1005. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  1006. <p><br>纵横通行帐号与你共成长!</p>
  1007. <p>' . date('Y年m月d日', time()) . '</p>
  1008. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  1009. </td></tr>
  1010. </tbody>
  1011. </table>';
  1012. $this->SMail($session->user['email'], $StrSubject, $StrContent);
  1013. }elseif($action == 2){
  1014. }
  1015. setcookie(Doo::conf()->COOKIEPRE . 'auth');
  1016. $session->user = array();
  1017. return $this->logout('msgRelogin');
  1018. }elseif($session->user['password'] != $this->create_password($_POST['oldpwd'], $session->user['salt'])){
  1019. $this->data['erroT']="erroT";
  1020. $this->data['erroTxt']='<span for="oldpwd" generated="true" class="erroT" style="">输入密码有误</span>';
  1021. $this->data['aerroT']="";
  1022. $this->data['aerroTxt']='';
  1023. $this->render($this->theme.'changePassword', $this->data);die;
  1024. }
  1025. // echo $session->user['id'];
  1026. }
  1027. $this->render($this->theme.'changePassword', $this->data);
  1028. }
  1029. // 加密
  1030. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  1031. $ckey_length = 4;
  1032. $key = md5($key != '' ? $key : Doo::conf()->AUTHKEY);
  1033. $keya = md5(substr($key, 0, 16));
  1034. $keyb = md5(substr($key, 16, 16));
  1035. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
  1036. $cryptkey = $keya . md5($keya . $keyc);
  1037. $key_length = strlen($cryptkey);
  1038. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
  1039. $string_length = strlen($string);
  1040. $result = '';
  1041. $box = range(0, 255);
  1042. $rndkey = array();
  1043. for ($i = 0; $i <= 255; $i++) {
  1044. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  1045. }
  1046. for ($j = $i = 0; $i < 256; $i++) {
  1047. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  1048. $tmp = $box[$i];
  1049. $box[$i] = $box[$j];
  1050. $box[$j] = $tmp;
  1051. }
  1052. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  1053. $a = ($a + 1) % 256;
  1054. $j = ($j + $box[$a]) % 256;
  1055. $tmp = $box[$a];
  1056. $box[$a] = $box[$j];
  1057. $box[$j] = $tmp;
  1058. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  1059. }
  1060. if ($operation == 'DECODE') {
  1061. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
  1062. return substr($result, 26);
  1063. } else {
  1064. return '';
  1065. }
  1066. } else {
  1067. return $keyc . str_replace('=', '', base64_encode($result));
  1068. }
  1069. }
  1070. /**
  1071. * 管理登出
  1072. */
  1073. function logout($msg=null) {
  1074. $session = Doo::session("sso");
  1075. unset($session->user);
  1076. session_destroy();
  1077. setcookie(Doo::conf()->COOKIEPRE . 'auth', null, 0, '/', Doo::conf()->APP_URL, 0);
  1078. setcookie(Doo::conf()->COOKIEPRE . '_userid', null, 0, '/', Doo::conf()->APP_URL, 0);
  1079. setcookie(Doo::conf()->COOKIEPRE . '_username', null, 0, '/', Doo::conf()->APP_URL, 0);
  1080. if(!empty($msg)){
  1081. return Doo::conf()->APP_URL . 'notic/relogin';
  1082. }else{
  1083. return Doo::conf()->APP_URL . 'msg/logout';
  1084. }
  1085. }
  1086. // 检测Email格式
  1087. function checkMail($email) {
  1088. //if (strlen($email) > 6 && preg_match('/^([\w-]+\.?)*\w+@[\w-]+\.[a-z]{2,6}$/', $email)) {
  1089. if (filter_var($email, FILTER_VALIDATE_EMAIL)){
  1090. return TRUE;
  1091. } else {
  1092. return FALSE;
  1093. }
  1094. }
  1095. // 检测手机格式
  1096. function checkMobile($mobile) {
  1097. if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){
  1098. return TRUE;
  1099. } else {
  1100. return FALSE;
  1101. }
  1102. }
  1103. function checkhadmobile() {
  1104. // TODO:检测手机号是否已注册通行账号
  1105. if (!empty($_POST['zhmobile'])){
  1106. }
  1107. }
  1108. function checkuser() {
  1109. if (!empty($_POST['zhemail']))
  1110. $checkemail = $_POST['zhemail'];
  1111. if (!empty($_POST['zhuser']))
  1112. $checkuser = $_POST['zhuser'];
  1113. if(!empty($_POST['zhmobile']))
  1114. $checkmobile = $_POST['zhmobile'];
  1115. if(!empty($_POST['zhsmscode']))
  1116. $checkcode = $_POST['zhsmscode'];
  1117. if (!empty($_POST['zhmuser']))
  1118. $checkuser = $_POST['zhmuser'];
  1119. if (!empty($_POST['password']))
  1120. $checkpassword = $_POST['password'];
  1121. if (!empty($checkemail))
  1122. if ($this->checkMail($checkemail)) {
  1123. $user = Doo::db()->find('users', array(
  1124. 'select' => 'id',
  1125. 'where' => 'useremail=?',
  1126. 'param' => array($checkemail),
  1127. )
  1128. );
  1129. if (empty($user)) {
  1130. exit('true');
  1131. } else {
  1132. exit('false');
  1133. }
  1134. }
  1135. if (!empty($checkuser))
  1136. if ($checkuser) {
  1137. // TODO:判断是否符合账号规则
  1138. $user = Doo::db()->find('users', array(
  1139. 'select' => 'id',
  1140. 'where' => 'username=?',
  1141. 'param' => array($checkuser),
  1142. )
  1143. );
  1144. if (empty($user)) {
  1145. exit('true');
  1146. } else {
  1147. exit('false');
  1148. }
  1149. }
  1150. if(!empty($checkcode) && !empty($checkmobile)){
  1151. //TODO:检测验证码
  1152. if($checkmobile && $checkcode) {
  1153. $now = time();
  1154. $old = $now-1800;
  1155. Doo::loadModel('mobilecode');
  1156. $mobilecode = new mobilecode();
  1157. $code = $mobilecode->find(array(
  1158. 'select' => 'id',
  1159. 'where' => 'mobile='.$checkmobile.' and code='.$checkcode.' and time between '.$old.' and '.$now,
  1160. 'desc' => 'id',
  1161. 'limit' => 1,
  1162. 'asArray' => true
  1163. ));
  1164. if ($code) {
  1165. exit('true');
  1166. } else {
  1167. exit('false');
  1168. }
  1169. }
  1170. }
  1171. if(!empty($checkmobile)){
  1172. if($checkmobile) {
  1173. // TODO:判断是否符合电话并且未注册
  1174. $user = Doo::db()->find('users', array(
  1175. 'select' => 'id',
  1176. 'where' => 'mobile=?',
  1177. 'param' => array($checkmobile),
  1178. )
  1179. );
  1180. if (empty($user)) {
  1181. exit('true');
  1182. } else {
  1183. exit('false');
  1184. }
  1185. }
  1186. }
  1187. if(!empty($checkpassword)){
  1188. if($checkpassword) {
  1189. $session = Doo::session("sso");
  1190. if ($session->user['password'] == $this->create_password($checkpassword, $session->user['salt'])) {
  1191. exit('true');
  1192. }else{
  1193. exit('false');
  1194. }
  1195. }
  1196. }
  1197. }
  1198. function checkphone(){
  1199. if(!empty($_POST['zhmobile']))
  1200. $checkmobile = $_POST['zhmobile'];
  1201. if(!empty($checkmobile)){
  1202. if($checkmobile) {
  1203. // TODO:判断是否符合电话并且已注册
  1204. $user = Doo::db()->find('users', array(
  1205. 'select' => 'id',
  1206. 'where' => 'mobile=?',
  1207. 'param' => array($checkmobile),
  1208. )
  1209. );
  1210. if (!empty($user)) {
  1211. exit('true');
  1212. } else {
  1213. exit('false');
  1214. }
  1215. }
  1216. }
  1217. }
  1218. public function checkemail() {
  1219. //TODO:其实检测唯一性就已经检测了当前用户Email
  1220. $session = Doo::session("sso");
  1221. if (empty($session->user['id'])) {
  1222. return Doo::conf()->APP_URL . 'error/loginFail';
  1223. }
  1224. $newEmail = isset($_POST['email']) ? $_POST['email'] : NULL;
  1225. if (!empty($newEmail) && $this->checkMail($newEmail)) {
  1226. $session = Doo::session("sso");
  1227. if ($newEmail == $session->user['email']) {
  1228. exit('false');
  1229. }
  1230. if (!$this->checkExsitmail($newEmail)) {
  1231. exit('false');
  1232. }
  1233. }
  1234. exit('true');
  1235. }
  1236. public function alipay(){
  1237. $session = Doo::session("sso");
  1238. if (empty($session->user['id'])) {
  1239. return Doo::conf()->APP_URL . 'error/loginFail';
  1240. }
  1241. if (!empty($_POST['remark2'])) {
  1242. Doo::loadModel('m/sale');
  1243. $saleObj = new Sale();
  1244. $rowNumber = $saleObj->count(array('where'=>'promocode=?','param' => array($_POST['remark2']),'asArray'=>TRUE));
  1245. if($rowNumber){
  1246. $this->data['remark2'] = $_POST['remark2'];
  1247. }else{
  1248. $this->data['remark2'] = NULL;
  1249. }
  1250. } else {
  1251. $this->data['remark2'] = NULL;
  1252. }
  1253. require_once(Doo::conf()->SITE_PATH."protected/class/alipay/alipay.config.php");
  1254. require_once(Doo::conf()->SITE_PATH."protected/class/alipay/lib/alipay_submit.class.php");
  1255. $alipaySubmit = new AlipaySubmit($alipay_config);
  1256. $payment_type = "1";
  1257. $notify_url = Doo::conf()->APP_URL."api/smartcost/sso/notify_url.php";
  1258. $return_url = Doo::conf()->APP_URL."api/smartcost/sso/return_url.php";
  1259. //商户订单号
  1260. $sn=$this->create_sn();
  1261. $out_trade_no = $sn;
  1262. $subject = '纵横通行账户充值';
  1263. $extra_common_param=$this->data['remark2']; //用户自定义回传参数
  1264. //付款金额
  1265. $p_amount=trim($_POST['p_amount']);
  1266. $total_fee = $p_amount;
  1267. $body = '';
  1268. $show_url = '';
  1269. //防钓鱼时间戳
  1270. $anti_phishing_key = $alipaySubmit->query_timestamp();
  1271. $exter_invoke_ip = $this->clientIP();
  1272. //构造要请求的参数数组,无需改动
  1273. $parameter = array(
  1274. "service" => "create_direct_pay_by_user",
  1275. "partner" => trim($alipay_config['partner']),
  1276. "seller_email" => trim($alipay_config['seller_email']),
  1277. "payment_type" => $payment_type,
  1278. "notify_url" => $notify_url,
  1279. "return_url" => $return_url,
  1280. "out_trade_no" => $out_trade_no,
  1281. "subject" => $subject,
  1282. "total_fee" => $total_fee,
  1283. "body" => $body,
  1284. "show_url" => $show_url,
  1285. "anti_phishing_key" => $anti_phishing_key,
  1286. "exter_invoke_ip" => $exter_invoke_ip,
  1287. "_input_charset" => trim(strtolower($alipay_config['input_charset'])),
  1288. "extra_common_param"=> $extra_common_param
  1289. );
  1290. //建立请求
  1291. $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "加载中");
  1292. // 生成订单
  1293. Doo::loadModel('pay');
  1294. $pay = new Pay();
  1295. $array = array('trade_sn' => $sn,
  1296. 'userid' => $session->user['id'],
  1297. 'username' => $session->user['username'],
  1298. 'telephone' => $this->data['remark2'],
  1299. 'money' => $p_amount,
  1300. 'addtime' => time(),
  1301. 'usernote' => $session->user['username'] . '[' . $sn . ']',
  1302. 'pay_type' => 'alipay',
  1303. 'payment' => '支付宝',
  1304. 'ip' => $this->clientIP(),
  1305. 'status' => 'unpay'
  1306. );
  1307. $pay->add($array);
  1308. header("Content-type: text/html; charset=utf-8");
  1309. echo $html_text;
  1310. }
  1311. function returnAlipay(){
  1312. $session = Doo::session("sso");
  1313. if (empty($session->user['id'])) {
  1314. return Doo::conf()->APP_URL . 'error/loginFail';
  1315. }
  1316. require_once(Doo::conf()->SITE_PATH."protected/class/alipay/alipay.config.php");
  1317. require_once(Doo::conf()->SITE_PATH."protected/class/alipay/lib/alipay_notify.class.php");
  1318. $alipayNotify = new AlipayNotify($alipay_config);
  1319. $verify_result = $alipayNotify->verifyReturn();
  1320. if($verify_result) {
  1321. $v_oid = $_GET['out_trade_no']; //商户订单号
  1322. $trade_no = $_GET['trade_no']; //支付宝交易号
  1323. $trade_status = $_GET['trade_status']; //交易状态
  1324. $v_amount=$_GET['total_fee']; //交易金额
  1325. $remark2 = $_GET['extra_common_param'];
  1326. if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
  1327. $pay = Doo::loadModel('pay', TRUE);
  1328. $callbackData = $pay->getRowsBySN($v_oid);
  1329. if ($callbackData['status'] == 'unpay') {
  1330. if ($callbackData['money'] == $v_amount) {
  1331. $pay->trade_sn = $v_oid;
  1332. $comment = $pay->find(array('limit' => 1, 'select' => 'id', 'asArray' => TRUE));
  1333. $pay->id = $comment['id'];
  1334. $pay->paytime = time();
  1335. $pay->status = 'succ';
  1336. $succvalue = $pay->update();
  1337. if ($succvalue) {
  1338. // 增加销售人员提成与折扣
  1339. if(!empty($remark2)&&($v_amount>=$this->cashlimit)){
  1340. $salerGet = floor($v_amount*$this->salelimit); // 计算销售人员获得的提成
  1341. $v_amount += floor($v_amount*$this->perlimit); // 计算输入优惠码的最终充值金额
  1342. Doo::loadModel('m/sale');
  1343. $saleObj = new Sale();
  1344. $saleObj->total = new DooDbExpression('total+' . $salerGet);
  1345. $saleObj->update(array('where'=>'promocode=?','param'=>array($remark2)));
  1346. }
  1347. Doo::loadModel('users');
  1348. $users = new Users();
  1349. $moneyValue = $users->updateBank($callbackData['userid'], $v_amount);
  1350. if ($moneyValue) {
  1351. $this->data['msg'] = '充值完成';
  1352. header('refresh:3;url=/');
  1353. }
  1354. //发送邮件
  1355. include ('./protected/class/email_templete.file.php');
  1356. //获取文档 $callbackData['userid']
  1357. $userinfo=$users->getRowByUid( $callbackData['userid']);
  1358. //$v_amount , $v_oid
  1359. $templete_email=$this->format_email_content($email_file['RECHARGE_SUCCESS'], "RECHARGE_SUCCESS",$v_amount,$userinfo,$v_oid);
  1360. //$templete_email['toemail']="cpthought@vip.qq.com";
  1361. if(filter_var($templete_email['toemail'], FILTER_VALIDATE_EMAIL))
  1362. $this->_mail($templete_email['templete'],$templete_email['subject'],$templete_email['toemail']);
  1363. }
  1364. }
  1365. } else {
  1366. $this->data['msg'] = '已充值完毕,操作无效';
  1367. header('refresh:3;url=/');
  1368. }
  1369. }
  1370. }else {
  1371. $this->data['msg'] = '充值故障';
  1372. header('refresh:3;url=/');
  1373. }
  1374. $this->render($this->theme.'recharge_msg', $this->data, TRUE);
  1375. }
  1376. function notifyAlipay(){
  1377. require_once(Doo::conf()->SITE_PATH."protected/class/alipay/alipay.config.php");
  1378. require_once(Doo::conf()->SITE_PATH."protected/class/alipay/lib/alipay_notify.class.php");
  1379. $alipayNotify = new AlipayNotify($alipay_config);
  1380. $verify_result = $alipayNotify->verifyNotify();
  1381. if($verify_result) {
  1382. $v_oid = $_POST['out_trade_no']; //商户订单号
  1383. $trade_no = $_POST['trade_no']; //支付宝交易号
  1384. $trade_status = $_POST['trade_status']; //交易状态
  1385. $v_amount=$_POST['total_fee']; //交易金额
  1386. $remark2 = $_POST['extra_common_param'];
  1387. if($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS') {
  1388. $pay = Doo::loadModel('pay', TRUE);
  1389. $callbackData = $pay->getRowsBySN($v_oid);
  1390. if ($callbackData['status'] == 'unpay') {
  1391. if ($callbackData['money'] == $v_amount) {
  1392. $pay->trade_sn = $v_oid;
  1393. $comment = $pay->find(array('limit' => 1, 'select' => 'id', 'asArray' => TRUE));
  1394. $pay->id = $comment['id'];
  1395. $pay->paytime = time();
  1396. $pay->status = 'succ';
  1397. $succvalue = $pay->update();
  1398. if ($succvalue) {
  1399. // 增加销售人员提成与折扣
  1400. if(!empty($remark2)&&($v_amount>=$this->cashlimit)){
  1401. $salerGet = floor($v_amount*$this->salelimit); // 计算销售人员获得的提成
  1402. $v_amount += floor($v_amount*$this->perlimit); // 计算输入优惠码的最终充值金额
  1403. Doo::loadModel('m/sale');
  1404. $saleObj = new Sale();
  1405. $saleObj->total = new DooDbExpression('total+' . $salerGet);
  1406. $saleObj->update(array('where'=>'promocode=?','param'=>array($remark2)));
  1407. }
  1408. Doo::loadModel('users');
  1409. $users = new Users();
  1410. $moneyValue = $users->updateBank($callbackData['userid'], $v_amount);
  1411. if ($moneyValue) {
  1412. Doo::loadModel('income_pay');
  1413. $incomepay = new IncomePay();
  1414. $incomepay->uid = $callbackData['userid'];
  1415. $incomepay->money = $v_amount;
  1416. $incomepay->type = 1;
  1417. $incomepay->comefrom = '支付宝';
  1418. $incomepay->addtime = time();
  1419. $incomepay->insert();
  1420. echo "success"; die;
  1421. }
  1422. //发送邮件
  1423. include ('./protected/class/email_templete.file.php');
  1424. //获取文档 $callbackData['userid']
  1425. $userinfo=$users->getRowByUid( $callbackData['userid']);
  1426. //$v_amount , $v_oid
  1427. $templete_email=$this->format_email_content($email_file['RECHARGE_SUCCESS'], "RECHARGE_SUCCESS",$v_amount,$userinfo,$v_oid);
  1428. //$templete_email['toemail']="cpthought@vip.qq.com";
  1429. if(filter_var($templete_email['toemail'], FILTER_VALIDATE_EMAIL))
  1430. $this->_mail($templete_email['templete'],$templete_email['subject'],$templete_email['toemail']);
  1431. }
  1432. }
  1433. }
  1434. }
  1435. echo "success";
  1436. }else {
  1437. echo "fail";
  1438. }
  1439. }
  1440. public function deposit2() {
  1441. $session = Doo::session("sso");
  1442. if (empty($session->user['id'])) {
  1443. return Doo::conf()->APP_URL . 'error/loginFail';
  1444. }
  1445. $sn = $this->create_sn();
  1446. if (isset($_POST['isubmit']) && isset($_POST['ibank']) && is_numeric($_POST['ibank'])) {
  1447. $money = intval($_POST['ibank']);
  1448. // if (preg_match('/^1[3458][0-9]{9}$/', $_POST['remark2'])) {
  1449. if (!empty($_POST['remark2'])) {
  1450. Doo::loadModel('m/sale');
  1451. $saleObj = new Sale();
  1452. $rowNumber = $saleObj->count(array('where'=>'promocode=?','param' => array($_POST['remark2']),'asArray'=>TRUE));
  1453. if($rowNumber){
  1454. $this->data['remark2'] = $_POST['remark2'];
  1455. }else{
  1456. $this->data['remark2'] = NULL;
  1457. }
  1458. } else {
  1459. $this->data['remark2'] = NULL;
  1460. }
  1461. Doo::loadModel('pay');
  1462. $pay = new Pay();
  1463. $array = array('trade_sn' => $sn, 'userid' => $session->user['id'], 'username' => $session->user['username'], 'money' => $money, 'telephone' => $this->data['remark2'], 'addtime' => time(), 'pay_type' => 'offline', 'payment' => '银行转账', 'ip' => $this->clientIP(), 'status' => 'waitting');
  1464. $pay->add($array);
  1465. $this->data['money'] = $money;
  1466. // header('refresh:2;url=' . Doo::conf()->APP_URL . 'deposit');
  1467. $this->render($this->theme.'bankConfirm', $this->data, TRUE);
  1468. die();
  1469. }
  1470. Doo::loadModel('users');
  1471. $users = new Users();
  1472. $valuebank = $users->getRowByUid($session->user['id']);
  1473. $this->data['bank'] = isset($valuebank[0]['bank']) ? $valuebank[0]['bank'] : 0;
  1474. $this->data['sn'] = $sn;
  1475. $this->data['usercat'] = NULL;
  1476. $this->data['extmenu'] = 0;
  1477. $this->data['FUN'] = __FUNCTION__;
  1478. if($session->user['id']){
  1479. $this->data['avatar'] = $this->ps_getavatar($session->user['id']);
  1480. }else{
  1481. $this->data['avatar'] = Doo::conf()->APP_URL . 'global/img/avatra48.png';
  1482. }
  1483. $this->data['name'] = $session->user['username'];
  1484. $this->render($this->theme.'recharge', $this->data, TRUE);
  1485. }
  1486. public function deposit3() {
  1487. $session = Doo::session("sso");
  1488. if (empty($session->user['id'])) {
  1489. return Doo::conf()->APP_URL . 'error/loginFail';
  1490. }
  1491. $bankArray = array(
  1492. /*'1025' => 'https://pay3.chinabank.com.cn/i/bank_gsyh2.gif',
  1493. '308' => 'https://pay3.chinabank.com.cn/i/bank_zsyh2.gif',
  1494. '105' => 'https://pay3.chinabank.com.cn/i/bank_jsyh2.gif',
  1495. '103' => 'https://pay3.chinabank.com.cn/i/bank_nyyh2.gif',
  1496. '104' => 'https://pay3.chinabank.com.cn/i/bank_zgyh2.gif',
  1497. '301' => 'https://pay3.chinabank.com.cn/i/bank_jtyh.gif',
  1498. '311' => 'https://pay3.chinabank.com.cn/i/bank_hxyh.gif',
  1499. '309' => 'https://pay3.chinabank.com.cn/i/bank_xyyh.gif',
  1500. '305' => 'https://pay3.chinabank.com.cn/i/bank_msyh2.gif',
  1501. '306' => 'https://pay3.chinabank.com.cn/i/bank_gdfz.gif',
  1502. '307' => 'https://pay3.chinabank.com.cn/i/bank_szfz.gif',
  1503. '314' => 'https://pay3.chinabank.com.cn/i/bank_pfyh.gif',
  1504. '313' => 'https://pay3.chinabank.com.cn/i/bank_zxyh.gif',
  1505. '312' => 'https://pay3.chinabank.com.cn/i/bank_gdyh.gif',
  1506. '316' => 'https://pay3.chinabank.com.cn/i/bank_njyh.gif',
  1507. '317' => 'https://pay3.chinabank.com.cn/i/bank_bhyh.gif',
  1508. '3279' => 'https://pay3.chinabank.com.cn/i/bank_psbc.gif',
  1509. '327' => 'https://pay3.chinabank.com.cn/i/bank_unionpay.gif'*/
  1510. '1025'=>'http://bank-logo.qiniudn.com/bank_gsyh2.gif',
  1511. '308'=>'http://bank-logo.qiniudn.com/bank_zsyh2.gif',
  1512. '105'=>'http://bank-logo.qiniudn.com/bank_jsyh2.gif',
  1513. '103'=>'http://bank-logo.qiniudn.com/bank_nyyh2.gif',
  1514. '104'=>'http://bank-logo.qiniudn.com/bank_zgyh2.gif',
  1515. '301'=>'http://bank-logo.qiniudn.com/bank_jtyh.gif',
  1516. '311'=>'http://bank-logo.qiniudn.com/bank_hxyh.gif',
  1517. '309'=>'http://bank-logo.qiniudn.com/bank_xyyh.gif',
  1518. '305'=>'http://bank-logo.qiniudn.com/bank_msyh2.gif',
  1519. '306'=>'http://bank-logo.qiniudn.com/bank_gdfz.gif',
  1520. '307'=>'http://bank-logo.qiniudn.com/bank_payh.gif',
  1521. '314'=>'http://bank-logo.qiniudn.com/bank_pfyh.gif',
  1522. '313'=>'http://bank-logo.qiniudn.com/bank_zxyh.gif',
  1523. '312'=>'http://bank-logo.qiniudn.com/bank_gdyh.gif',
  1524. '316'=>'http://bank-logo.qiniudn.com/bank_njyh.gif',
  1525. '3230'=>'http://bank-logo.qiniudn.com/bank_psbc.gif',
  1526. '324'=>'http://bank-logo.qiniudn.com/bank_hangzhou.jpg',
  1527. '302'=>'http://bank-logo.qiniudn.com/bank_nbyh.gif',
  1528. '310'=>'http://bank-logo.qiniudn.com/bank_bj.gif',
  1529. '342'=>'http://bank-logo.qiniudn.com/bank_CQRCB.gif',
  1530. '343'=>'http://bank-logo.qiniudn.com/bank_SRCB.gif',
  1531. '335'=>'http://bank-logo.qiniudn.com/bank_BJRCB.gif',
  1532. '3341'=>'http://bank-logo.qiniudn.com/bank_QDCCB.gif',
  1533. '336'=>'http://bank-logo.qiniudn.com/bank_BOCD.gif',
  1534. );
  1535. $banKey = array_keys($bankArray);
  1536. if (isset($_POST['v_amount']) && isset($_POST['bank']) && in_array($_POST['bank'], $banKey)) {
  1537. $this->data['v_amount'] = $_POST['v_amount'];
  1538. $this->data['bankid'] = $_POST['bank'];
  1539. $this->data['bankinfo'] = $bankArray[$this->data['bankid']];
  1540. } else {
  1541. return Doo::conf()->APP_URL . 'depositnew';
  1542. }
  1543. $this->data['usercat'] = NULL;
  1544. $this->data['extmenu'] = 0;
  1545. Doo::loadModel('users');
  1546. $users = new Users();
  1547. $valuebank = $users->getRowByUid($session->user['id']);
  1548. $this->data['bank'] = isset($valuebank[0]['bank']) ? $valuebank[0]['bank'] : 0;
  1549. $this->data['FUN'] = __FUNCTION__;
  1550. if($session->user['id']){
  1551. $this->data['avatar'] = $this->ps_getavatar($session->user['id']);
  1552. }else{
  1553. $this->data['avatar'] = Doo::conf()->APP_URL . 'global/img/avatra48.png';
  1554. }
  1555. $this->render($this->theme.'recharge2', $this->data, TRUE);
  1556. }
  1557. /**
  1558. * 生成流水号
  1559. */
  1560. function create_sn() {
  1561. mt_srand((double) microtime() * 1000000);
  1562. return date("YmdHis") . str_pad(mt_rand(1, 99999), 5, "0", STR_PAD_LEFT);
  1563. }
  1564. public function send() {
  1565. // TODO:20130312
  1566. // TODO:没有检验金额,是否额定
  1567. // TODO:请求链接来源验证
  1568. // TODO:防止暴力提交订单
  1569. // TODO:检测是否存在为支付订单,防止重复提交
  1570. // TODO:增加销售人员手机号作为优惠码20130503
  1571. $session = Doo::session("sso");
  1572. if (empty($session->user['id'])) {
  1573. return Doo::conf()->APP_URL . 'error/loginFail';
  1574. }
  1575. $this->data['v_oid'] = $this->create_sn();
  1576. $this->data['v_mid'] = '22544863'; // 商户号,这里为测试商户号1001,替换为自己的商户号(老版商户号为4位或5位,新版为8位)即可
  1577. $this->data['v_url'] = 'http://sso.smartcost.com.cn/Receive'; // 请填写返回url,地址应为绝对路径,带有http协议
  1578. $this->data['v_return'] = 'http://sso.smartcost.com.cn'; // 请填写返回url,地址应为绝对路径,带有http协议
  1579. $this->data['key'] = 'smartcost@)!@onlinepaychinabank'; // 如果您还没有设置MD5密钥请登陆我们为您提供商户后台,地址:https://merchant3.chinabank.com.cn/
  1580. $this->data['v_amount'] = trim($_POST['v_amount']); //支付金额
  1581. $this->data['v_moneytype'] = "CNY"; //币种
  1582. $this->data['text'] = $this->data['v_amount'] . $this->data['v_moneytype'] . $this->data['v_oid'] . $this->data['v_mid'] . $this->data['v_url'] . $this->data['key']; //md5加密拼凑串,注意顺序不能变
  1583. $this->data['v_md5info'] = strtoupper(md5($this->data['text'])); //md5函数加密并转化成大写字母
  1584. if (isset($_POST['bank'])) {
  1585. $this->data['bank'] = trim($_POST['bank']); //md5函数加密并转化成大写字母
  1586. } else {
  1587. $this->data['bank'] = NULL;
  1588. }
  1589. // $this->data['remark2'] = isset($_POST['remark2']) ? trim($_POST['remark2']) : NULL; //备注字段2
  1590. // if (preg_match('/^1[3458][0-9]{9}$/', $_POST['remark2'])) {
  1591. if (!empty($_POST['remark2'])) {
  1592. Doo::loadModel('m/sale');
  1593. $saleObj = new Sale();
  1594. $rowNumber = $saleObj->count(array('where'=>'promocode=?','param' => array($_POST['remark2']),'asArray'=>TRUE));
  1595. if($rowNumber){
  1596. $this->data['remark2'] = $_POST['remark2'];
  1597. }else{
  1598. $this->data['remark2'] = NULL;
  1599. }
  1600. } else {
  1601. $this->data['remark2'] = NULL;
  1602. }
  1603. // 生成订单
  1604. Doo::loadModel('pay');
  1605. $pay = new Pay();
  1606. $array = array('trade_sn' => $this->data['v_oid'], 'userid' => $session->user['id'], 'username' => $session->user['username'], 'telephone' => $this->data['remark2'], 'money' => $this->data['v_amount'], 'addtime' => time(), 'usernote' => $session->user['username'] . '[' . $this->data['v_oid'] . ']', 'pay_type' => 'recharge', 'payment' => '网银在线', 'ip' => $this->clientIP(), 'status' => 'unpay','pay_id'=>$this->data['bank']);
  1607. $pay->add($array);
  1608. $this->data['remark1'] = $this->getUserName() . '[' . $this->data['v_oid'] . ']'; //备注字段1
  1609. $this->data['v_rcvname'] = isset($_POST['v_rcvname']) ? trim($_POST['v_rcvname']) : NULL; // 收货人
  1610. $this->data['v_rcvaddr'] = isset($_POST['v_rcvaddr']) ? trim($_POST['v_rcvaddr']) : NULL; // 收货地址
  1611. $this->data['v_rcvtel'] = isset($_POST['v_rcvtel']) ? trim($_POST['v_rcvtel']) : NULL; // 收货人电话
  1612. $this->data['v_rcvpost'] = isset($_POST['v_rcvpost']) ? trim($_POST['v_rcvpost']) : NULL; // 收货人邮编
  1613. $this->data['v_rcvemail'] = isset($_POST['v_rcvemail']) ? trim($_POST['v_rcvemail']) : NULL; // 收货人邮件
  1614. $this->data['v_rcvmobile'] = isset($_POST['v_rcvmobile']) ? trim($_POST['v_rcvmobile']) : NULL; // 收货人手机号
  1615. $this->data['v_ordername'] = isset($_POST['v_ordername']) ? trim($_POST['v_ordername']) : NULL; // 订货人姓名
  1616. $this->data['v_orderaddr'] = isset($_POST['v_orderaddr']) ? trim($_POST['v_orderaddr']) : NULL; // 订货人地址
  1617. $this->data['v_ordertel'] = isset($_POST['v_ordertel']) ? trim($_POST['v_ordertel']) : NULL; // 订货人电话
  1618. $this->data['v_orderpost'] = isset($_POST['v_orderpost']) ? trim($_POST['v_orderpost']) : NULL; // 订货人邮编
  1619. $this->data['v_orderemail'] = isset($_POST['v_orderemail']) ? trim($_POST['v_orderemail']) : NULL; // 订货人邮件
  1620. $this->data['v_ordermobile'] = isset($_POST['v_ordermobile']) ? trim($_POST['v_ordermobile']) : NULL; // 订货人手机号
  1621. $this->render($this->theme.'send', $this->data, TRUE);
  1622. }
  1623. // 手动对账
  1624. public function receive() {
  1625. $session = Doo::session("sso");
  1626. if (empty($session->user['id'])) {
  1627. return Doo::conf()->APP_URL . 'error/loginFail';
  1628. }
  1629. $key = 'smartcost@)!@onlinepaychinabank';
  1630. $v_oid = isset($_POST['v_oid']) ? trim($_POST['v_oid']) : NULL; // 商户发送的v_oid定单编号
  1631. $v_pmode = isset($_POST['v_pmode']) ? trim($_POST['v_pmode']) : NULL; // 支付方式(字符串)
  1632. $v_pstatus = isset($_POST['v_pstatus']) ? trim($_POST['v_pstatus']) : NULL; // 支付状态 :20(支付成功);30(支付失败)
  1633. $v_pstring = isset($_POST['v_pstring']) ? trim($_POST['v_pstring']) : NULL; // 支付结果信息 : 支付完成(当v_pstatus=20时);失败原因(当v_pstatus=30时,字符串);
  1634. $v_amount = isset($_POST['v_amount']) ? trim($_POST['v_amount']) : NULL; // 订单实际支付金额
  1635. $v_moneytype = isset($_POST['v_moneytype']) ? trim($_POST['v_moneytype']) : NULL; //订单实际支付币种
  1636. $remark1 = isset($_POST['remark1']) ? trim($_POST['remark1']) : NULL; //备注字段1
  1637. $remark2 = isset($_POST['remark2']) ? trim($_POST['remark2']) : NULL; //备注字段2
  1638. $v_md5str = isset($_POST['v_md5str']) ? trim($_POST['v_md5str']) : NULL; //拼凑后的MD5校验值
  1639. // echo $v_oid . '|' . $v_pstatus . '|' . $v_amount . '|' . $v_moneytype . '|' . $key;
  1640. /**
  1641. * 重新计算md5的值
  1642. * // 增加优惠信息
  1643. */
  1644. $md5string = strtoupper(md5($v_oid . $v_pstatus . $v_amount . $v_moneytype . $key)); //拼凑加密串
  1645. if ($v_md5str == $md5string) {
  1646. if ($v_pstatus == '20') {
  1647. $pay = Doo::loadModel('pay', TRUE);
  1648. $callbackData = $pay->getRowsBySN($v_oid);
  1649. if ($callbackData['status'] == 'unpay') {
  1650. if ($callbackData['money'] == $v_amount) {
  1651. $pay->trade_sn = $v_oid;
  1652. $comment = $pay->find(array('limit' => 1, 'select' => 'id', 'asArray' => TRUE));
  1653. $pay->id = $comment['id'];
  1654. $pay->paytime = time();
  1655. $pay->status = 'succ';
  1656. $succvalue = $pay->update();
  1657. Doo::loadModel('income_pay');
  1658. $incomepay = new IncomePay();
  1659. $incomepay->uid = $session->user['id'];
  1660. $incomepay->money = $v_amount;
  1661. $incomepay->type = 1;
  1662. $incomepay->comefrom = '网银在线';
  1663. $incomepay->addtime = time();
  1664. $incomepay->insert();
  1665. if ($succvalue) {
  1666. // 增加销售人员提成与折扣
  1667. if(!empty($remark2)&&($v_amount>=$this->cashlimit)){
  1668. $salerGet = floor($v_amount*$this->salelimit); // 计算销售人员获得的提成
  1669. $v_amount += floor($v_amount*$this->perlimit); // 计算输入优惠码的最终充值金额
  1670. Doo::loadModel('m/sale');
  1671. $saleObj = new Sale();
  1672. $saleObj->total = new DooDbExpression('total+' . $salerGet);
  1673. $saleObj->update(array('where'=>'promocode=?','param'=>array($remark2)));
  1674. }
  1675. Doo::loadModel('users');
  1676. $users = new Users();
  1677. $moneyValue = $users->updateBank($callbackData['userid'], $v_amount);
  1678. if ($moneyValue) {
  1679. $this->data['msg'] = '充值完成';
  1680. header('refresh:3;url=/');
  1681. }
  1682. //发送邮件
  1683. include ('./protected/class/email_templete.file.php');
  1684. //获取文档 $callbackData['userid']
  1685. $userinfo=$users->getRowByUid( $callbackData['userid']);
  1686. //$v_amount , $v_oid
  1687. $templete_email=$this->format_email_content($email_file['RECHARGE_SUCCESS'], "RECHARGE_SUCCESS",$v_amount,$userinfo,$v_oid);
  1688. //$templete_email['toemail']="cpthought@vip.qq.com";
  1689. if(filter_var($templete_email['toemail'], FILTER_VALIDATE_EMAIL))
  1690. $this->_mail($templete_email['templete'],$templete_email['subject'],$templete_email['toemail']);
  1691. }
  1692. }
  1693. } else {
  1694. $this->data['msg'] = '已充值完毕,操作无效';
  1695. header('refresh:3;url=/');
  1696. }
  1697. }
  1698. } else {
  1699. $this->data['msg'] = '充值故障';
  1700. header('refresh:3;url=/');
  1701. }
  1702. $this->render($this->theme.'recharge_msg', $this->data, TRUE);
  1703. }
  1704. /**
  1705. * 判断email格式是否正确
  1706. * @param $string email
  1707. */
  1708. public function getUserID() {
  1709. $userid = self::get_cookie('_userid');
  1710. if ($userid) {
  1711. return $userid;
  1712. } else {
  1713. return FALSE;
  1714. }
  1715. }
  1716. public function getUserName() {
  1717. $username = self::get_cookie('_username');
  1718. if ($username) {
  1719. return $username;
  1720. } else {
  1721. return FALSE;
  1722. }
  1723. }
  1724. public function get_cookie($var, $default = '') {
  1725. $varvar = Doo::conf()->COOKIEPRE . $var;
  1726. return isset($_COOKIE[$varvar]) ? $this->authcode($_COOKIE[$varvar], 'DECODE') : $default;
  1727. }
  1728. public function issafe() {
  1729. $session = Doo::session("sso");
  1730. if (empty($session->user['id'])) {
  1731. return Doo::conf()->APP_URL . 'error/loginFail';
  1732. }
  1733. if ($this->checkUserQuestionExs($session->user['id'])) {
  1734. return Doo::conf()->APP_URL . 'profile';
  1735. }
  1736. if (!empty($_POST['isubmit'])) {
  1737. $userquestion = htmlspecialchars($_POST['zhq']);
  1738. $defquestion = addslashes(htmlspecialchars($_POST['defq']));
  1739. $useranswer = addslashes(htmlspecialchars($_POST['zhanswer']));
  1740. if (in_array($userquestion, array(1, 2, 3, 4, 5, 6))) {
  1741. Doo::loadModel('users');
  1742. $users = new Users();
  1743. if (($userquestion == 6) && !empty($defquestion)) {
  1744. $users->defquestion = $defquestion;
  1745. }
  1746. $users->userquestion = $userquestion;
  1747. $users->useranswer = $useranswer;
  1748. $users->update(array('where' => 'id=' . $session->user['id']));
  1749. $session->user['userquestion'] = $userquestion;
  1750. return Doo::conf()->APP_URL . 'profile';
  1751. }
  1752. }
  1753. $this->data['avatar'] = $this->url_exists($this->ps_getavatar($session->user['id'])) ? $this->ps_getavatar($session->user['id']) : Doo::conf()->APP_URL . 'global/img/avatra48.png';
  1754. $this->data['qArray'] = $this->QArray;
  1755. $this->render($this->theme.'oldAunRe', $this->data, TRUE);
  1756. }
  1757. public function saveSafe() {
  1758. // $data = array('str' => '你好测试一下好不好用', 1 => 2, 2 => 3);
  1759. //// var_dump($data);
  1760. //// serialize
  1761. // $msg = msgpack_pack($data);
  1762. //
  1763. //// hexadecimal
  1764. // $str = unpack('H*', $msg);
  1765. // var_dump($str);
  1766. //// deserialize
  1767. //// $ret = msgpack_unpack($msg);
  1768. //// var_dump($ret);
  1769. $this->data['qArray'] = $this->QArray;
  1770. $this->render($this->theme.'oldAunRe', $this->data, TRUE);
  1771. }
  1772. public function pay() {
  1773. $session = Doo::session("sso");
  1774. if (empty($session->user['id'])) {
  1775. return Doo::conf()->APP_URL . 'error/loginFail';
  1776. }
  1777. Doo::loadModel('users');
  1778. $users = new Users();
  1779. $valuebank = $users->getRowByUid($session->user['id']);
  1780. $this->data['bank'] = isset($valuebank[0]['bank']) ? $valuebank[0]['bank'] : 0;
  1781. $this->data['name'] = $session->user['username'];
  1782. $this->data['avatar'] = $this->url_exists($this->ps_getavatar($session->user['id'])) ? $this->ps_getavatar($session->user['id']) : Doo::conf()->APP_URL . 'global/img/avatra48.png';
  1783. $this->render($this->theme.'toCash2', $this->data, TRUE);
  1784. }
  1785. public function ps_getavatar($uid) {
  1786. $dir1 = ceil($uid / 10000);
  1787. $dir2 = ceil($uid % 10000 / 1000);
  1788. $url = Doo::conf()->APP_URL . 'data/avatar/' . $dir1 . '/' . $dir2 . '/' . $uid . '/';
  1789. $avatar = array('180' => $url . '180x180.jpg', '90' => $url . '90x90.jpg', '45' => $url . '45x45.jpg', '30' => $url . '30x30.jpg');
  1790. return $avatar['45'];
  1791. }
  1792. // Not activated 未激活状态更改邮箱
  1793. public function nactChangMail() {
  1794. $session = Doo::session("sso");
  1795. $this->data['name'] = $session->user['username'];
  1796. if (empty($session->user['id'])) {
  1797. return Doo::conf()->APP_URL . 'error/loginFail';
  1798. }
  1799. if (self::isUserActive($session->user['id']))
  1800. return Doo::conf()->APP_URL . 'error/actuser';
  1801. if (isset($_POST['isubmit'])) {
  1802. $ismail = $this->checkMail($_POST['nactmail']);
  1803. if (!$ismail)
  1804. return Doo::conf()->APP_URL . 'error/erroremail';
  1805. $isok = $this->checkExsitmail($_POST['nactmail']);
  1806. if (!$isok || ($session->user['useremail'] == $_POST['nactmail']))
  1807. return Doo::conf()->APP_URL . 'error/userdemail';
  1808. $users = Doo::loadModel('users', true);
  1809. $users->id = $session->user['id'];
  1810. $users->useremail = $_POST['nactmail'];
  1811. $succvalue = $users->update();
  1812. if ($succvalue) {
  1813. Doo::loadModel('userswitch');
  1814. $UserSwitch = new UserSwitch();
  1815. $usArray = $UserSwitch->getOne(array('where' => 'uid=?', 'param' => array($session->user['id']), 'asArray' => TRUE));
  1816. $StrSubject = '纵横通行帐号-请激活您的帐号';
  1817. $StrContent = '<table style="width:100%">
  1818. <tbody>
  1819. <tr>
  1820. <td>
  1821. <p>感谢您注册成为纵横通行帐号的会员。在使用我们提供的服务之前,请点击以下链接,或将以下链接复制到浏览器的地址栏中打开,以激活您的帐户:</p>
  1822. <p style="width:600px"><br><a href="' . Doo::conf()->APP_URL . 'actuser/' . md5($session->user['id'] . $usArray['rndcode']) . '">' . Doo::conf()->APP_URL . 'actuser/' . md5($session->user['id'] . $usArray['rndcode']) . '</a></p>
  1823. <p><br>您之所以收到这封邮件,是因为您曾经注册成为纵横通行帐号的用户。我们保证仅向您发送关于纵横通行帐号的电子邮件。我们尊重并保护您的隐私。</p>
  1824. <p><br>纵横通行帐号与你共成长!</p>
  1825. <p>' . date('Y年m月d日', time()) . '</p>
  1826. <p>&copy;2012 <a href="http://smartcost.com.cn">珠海纵横创新软件有限公司</a></p>
  1827. </td>
  1828. </tr>
  1829. </tbody>
  1830. </table>';
  1831. $this->SMail($_POST['nactmail'], $StrSubject, $StrContent);
  1832. $this->data['nowmail'] = $session->user['email'] = $_POST['nactmail'];
  1833. $this->render($this->theme.'mailConfirm', $this->data, TRUE);
  1834. exit();
  1835. } else {
  1836. $this->render($this->theme.'newMailch', $this->data, TRUE);
  1837. exit();
  1838. }
  1839. }
  1840. $this->render($this->theme.'newMailch', $this->data, TRUE);
  1841. }
  1842. public function regMobile(){
  1843. $this->render($this->theme.'registerMobile', $this->data, TRUE);
  1844. }
  1845. public function getPWMobile(){
  1846. $this->render($this->theme.'getPassword-mobile', $this->data, TRUE);
  1847. }
  1848. public function setPWMobile() {
  1849. if($this->checkSmsCode($_POST['zhmobile'],$_POST['zhsmscode'])){
  1850. $user = Doo::db()->find('users', array(
  1851. 'select' => 'id,salt,username,mobile',
  1852. 'where' => 'mobile=?',
  1853. 'param' => array($_POST['zhmobile'])
  1854. )
  1855. );
  1856. if(!empty($user)){
  1857. $this->data['userid'] = $user[0]->id;
  1858. $this->data['usersalt'] = $user[0]->salt;
  1859. $this->render($this->theme.'getPassword-mobile2', $this->data, TRUE);
  1860. die;
  1861. } else {
  1862. $this->data['messages'] = '手机号有误,请重新输入';
  1863. }
  1864. }else{
  1865. $this->data['messages'] = '验证码过期或不一致,请重新获取';
  1866. }
  1867. $this->render($this->theme.'getPassword-mobile', $this->data, TRUE);
  1868. }
  1869. public function successPW(){
  1870. if(isset($_POST['userid'])){
  1871. // TODO:重新设置密码过程
  1872. $newPasswdStr = $_POST['password'];
  1873. $newPasswd = $this->create_password($newPasswdStr, $_POST['usersalt']);
  1874. $usersObj = Doo::loadModel('users', TRUE);
  1875. $usersObj->id = $_POST['userid'];
  1876. $usersObj->userpasswd = $newPasswd;
  1877. if ($usersObj->update()) {
  1878. $this->render($this->theme . 'getPassword-mobile-success', $this->data, TRUE);
  1879. die;
  1880. }else{
  1881. $this->data['messages'] = '新密码有误,请重新输入';
  1882. $this->data['userid'] = $_POST['userid'];
  1883. $this->data['usersalt'] = $_POST['usersalt'];
  1884. $this->render($this->theme.'getPassword-mobile2', $this->data, TRUE);
  1885. die;
  1886. }
  1887. }
  1888. return '/mobile/getpasswd';
  1889. }
  1890. public function Voucher(){
  1891. $session = Doo::session("sso");
  1892. if (empty($session->user['id'])) {
  1893. return Doo::conf()->APP_URL . 'error/loginFail';
  1894. }
  1895. Doo::loadModel('voucher');
  1896. Doo::loadModel('users');
  1897. $voucher = new Voucher();
  1898. if(isset($_POST['code'])){
  1899. $vinfo = $voucher->getRowbyCode($_POST['code']);
  1900. if(!empty($vinfo) && isset($vinfo['vstarttime']) && $vinfo['vstarttime'] <= time()){
  1901. Doo::loadModel('users_voucher');
  1902. $usersvoucher = new UsersVoucher();
  1903. $hadnum = $usersvoucher->count(array('where' => 'vid='.$vinfo['id']));
  1904. if($vinfo['vendtime'] < time() || ($vinfo['vcount'] != 0 && $hadnum >= $vinfo['vcount'])){
  1905. $this->data['pnote'] = '领取码"'.$_POST['code'].'"的活动已结束';
  1906. }else{
  1907. $checktake = $usersvoucher->checkuser($session->user['id'],$vinfo['id']);
  1908. if(!$checktake){
  1909. $this->data['pnote'] = '领取码"'.$_POST['code'].'"的活动您已参加,不可再次领取';
  1910. }else{
  1911. $usersvoucher->userid = $session->user['id'];
  1912. $usersvoucher->vid = $vinfo['id'];
  1913. $usersvoucher->vmoney = $vinfo['vcost'];
  1914. $usersvoucher->addtime = time();
  1915. $usersvoucher->vname = $vinfo['vname'];
  1916. $usersvoucher->insert();
  1917. Doo::loadModel('pay');
  1918. $pay = new Pay();
  1919. $array = array(
  1920. 'trade_sn' => $this->create_sn(),
  1921. 'userid' => $session->user['id'],
  1922. 'username' => $session->user['username'],
  1923. 'money' => $vinfo['vcost'],
  1924. 'addtime' => time(),
  1925. 'usernote' => $session->user['username'] . '[' . $this->create_sn() . ']',
  1926. 'pay_type' => 'voucher',
  1927. 'payment' => $vinfo['vname'],
  1928. 'ip' => $this->clientIP(),
  1929. 'status' => 'succ'
  1930. );
  1931. $pay->add($array);
  1932. $user = new Users();
  1933. $k=$user->updateBank($session->user['id'], $vinfo['vcost']);
  1934. if($k){
  1935. Doo::loadModel('income_pay');
  1936. $incomepay = new IncomePay();
  1937. $incomepay->uid = $session->user['id'];
  1938. $incomepay->money = $vinfo['vcost'];
  1939. $incomepay->type = 1;
  1940. $incomepay->comefrom = '代金券';
  1941. $incomepay->description = $vinfo['vname'];
  1942. $incomepay->addtime = time();
  1943. $incomepay->insert();
  1944. $this->data['pnote'] = '您成功领取了"'.$_POST['code'].'"领取码的活动';
  1945. }
  1946. }
  1947. }
  1948. }else{
  1949. $this->data['pnote'] = '没有"'.$_POST['code'].'"领取码的活动';
  1950. }
  1951. }
  1952. Doo::loadModel('users_voucher');
  1953. $uvou = new UsersVoucher();
  1954. $this->data['uvounum'] = $uvou->count(array('where' => 'userid='.$session->user['id'], 'asArray' => TRUE));
  1955. $uvoulist = $uvou->getvoucher($session->user['id'],20);
  1956. if(!empty($uvoulist)){
  1957. $this->data['uvoulist'] = $uvoulist;
  1958. }
  1959. $users = new Users();
  1960. $valuebank = $users->getRowByUid($session->user['id']);
  1961. $this->data['bank'] = isset($valuebank[0]['bank']) ? $valuebank[0]['bank'] : 0;
  1962. $this->data['name'] = $session->user['username'];
  1963. // $this->data['avatar'] = $this->url_exists($this->ps_getavatar($session->user['id'])) ? $this->ps_getavatar($session->user['id']) : Doo::conf()->APP_URL . 'global/img/avatra48.png';
  1964. if(isset($session->user['id'])){
  1965. $this->data['avatar'] = $this->ps_getavatar($session->user['id']);
  1966. }else{
  1967. $this->data['avatar'] = Doo::conf()->APP_URL . 'global/img/avatra48.png';
  1968. }
  1969. $this->data['FUN'] = 'voucher';
  1970. $this->render($this->theme.'voucher', $this->data, TRUE);
  1971. }
  1972. public function getVoucherMsg(){
  1973. $session = Doo::session("sso");
  1974. if (empty($session->user['id'])) {
  1975. return Doo::conf()->APP_URL . 'error/loginFail';
  1976. }
  1977. if(isset($this->params['pindex']) && is_numeric($this->params['pindex'])) {
  1978. Doo::loadModel('users_voucher');
  1979. $uvou = new UsersVoucher();
  1980. $limit = ($this->params['pindex']*20).',20';
  1981. $uvoulist = $uvou->getvoucher($session->user['id'], $limit);
  1982. if (!empty($uvoulist)) {
  1983. $uvounum = $uvou->count(array('where' => 'userid='.$session->user['id'], 'asArray' => TRUE));
  1984. $num = 0;
  1985. if($this->params['pindex']*20+20 < $uvounum){
  1986. $num = $this->params['pindex']+1;
  1987. };
  1988. foreach($uvoulist as $k => $v){
  1989. $uvoulist[$k]['addtime'] = date("Y-m-d H:i:s",$v['addtime']);
  1990. }
  1991. echo json_encode(array('code' => 200, 'uvoulist' => $uvoulist, 'num' => $num));
  1992. exit;
  1993. }
  1994. }
  1995. echo json_encode(array('code' => 400));
  1996. exit;
  1997. }
  1998. public function Order(){
  1999. $session = Doo::session("sso");
  2000. if (empty($session->user['id'])) {
  2001. return Doo::conf()->APP_URL . 'error/loginFail';
  2002. }
  2003. Doo::loadModel('income_pay');
  2004. $incomepay = new IncomePay();
  2005. $this->data['incomepaynum'] = $incomepay->count(array('where' => 'uid='.$session->user['id'], 'asArray' => TRUE));
  2006. $incomepaylist = $incomepay->get_listbyuid($session->user['id'],20);
  2007. if(!empty($incomepaylist)){
  2008. $this->data['incomepaylist'] = $incomepaylist;
  2009. }
  2010. Doo::loadModel('users');
  2011. $users = new Users();
  2012. $valuebank = $users->getRowByUid($session->user['id']);
  2013. $this->data['bank'] = isset($valuebank[0]['bank']) ? $valuebank[0]['bank'] : 0;
  2014. $this->data['name'] = $session->user['username'];
  2015. // $this->data['avatar'] = $this->url_exists($this->ps_getavatar($session->user['id'])) ? $this->ps_getavatar($session->user['id']) : Doo::conf()->APP_URL . 'global/img/avatra48.png';
  2016. if(isset($session->user['id'])){
  2017. $this->data['avatar'] = $this->ps_getavatar($session->user['id']);
  2018. }else{
  2019. $this->data['avatar'] = Doo::conf()->APP_URL . 'global/img/avatra48.png';
  2020. }
  2021. $this->data['FUN'] = '';
  2022. $this->render($this->theme.'order', $this->data, TRUE);
  2023. }
  2024. public function getOrderMsg(){
  2025. $session = Doo::session("sso");
  2026. if (empty($session->user['id'])) {
  2027. return Doo::conf()->APP_URL . 'error/loginFail';
  2028. }
  2029. if(isset($this->params['pindex']) && is_numeric($this->params['pindex'])) {
  2030. Doo::loadModel('income_pay');
  2031. $incomepay = new IncomePay();
  2032. $limit = ($this->params['pindex']*20).',20';
  2033. $incomepaylist = $incomepay->get_listbyuid($session->user['id'], $limit);
  2034. if (!empty($incomepaylist)) {
  2035. $incomepaynum = $incomepay->count(array('where' => 'uid='.$session->user['id'], 'asArray' => TRUE));
  2036. $num = 0;
  2037. if($this->params['pindex']*20+20 < $incomepaynum){
  2038. $num = $this->params['pindex']+1;
  2039. };
  2040. foreach($incomepaylist as $k => $v){
  2041. $incomepaylist[$k]['addtime'] = date("Y-m-d H:i:s",$v['addtime']);
  2042. }
  2043. echo json_encode(array('code' => 200, 'incomepaylist' => $incomepaylist, 'num' => $num));
  2044. exit;
  2045. }
  2046. }
  2047. echo json_encode(array('code' => 400));
  2048. exit;
  2049. }
  2050. private function checkExsitmail($email) {
  2051. $users = Doo::loadModel('users', true);
  2052. $arruser = $users->getOne(array('select' => 'id', 'where' => 'useremail=?', 'param' => array($email), 'asArray' => TRUE));
  2053. if (empty($arruser)) {
  2054. return TRUE;
  2055. } else {
  2056. return FALSE;
  2057. }
  2058. }
  2059. private function checkExsitMobile($mobile) {
  2060. $users = Doo::loadModel('users', true);
  2061. $arruser = $users->getOne(array('select' => 'id', 'where' => 'mobile=?', 'param' => array($mobile), 'asArray' => TRUE));
  2062. if (empty($arruser)) {
  2063. return TRUE;
  2064. } else {
  2065. return FALSE;
  2066. }
  2067. }
  2068. private function checkUserQuestion($uid) {
  2069. $ddd = Doo::loadModel('users', true);
  2070. $arruser = $ddd->getOne(array('select' => 'userquestion', 'where' => 'id=?', 'param' => array($uid), 'limit' => '1', 'asArray' => TRUE));
  2071. if (empty($arruser['userquestion'])) {
  2072. return TRUE;
  2073. } else {
  2074. return FALSE;
  2075. }
  2076. }
  2077. private function checkUserQuestionExs($uid) {
  2078. $ddd = Doo::loadModel('users', true);
  2079. $arruser = $ddd->getOne(array('select' => 'userquestion', 'where' => 'id=?', 'param' => array($uid), 'limit' => '1', 'asArray' => TRUE));
  2080. if ($arruser['userquestion']) {
  2081. return TRUE;
  2082. }
  2083. }
  2084. private static function isUserActive($uid) {
  2085. Doo::loadModel('userswitch');
  2086. $userswitch = new UserSwitch();
  2087. return $userswitch->checkUserStatus($uid);
  2088. }
  2089. /**
  2090. * 发送email
  2091. * @param unknown_type $html_templete
  2092. * @param unknown_type $subject
  2093. * @param unknown_type $toemail
  2094. */
  2095. function _mail( $html_templete = "",$subject="",$toemail=""){
  2096. require_once './protected/class/class.pop3.php';
  2097. require_once './protected/class/class.smtp.php';
  2098. require_once './protected/class/class.phpmailer.php';
  2099. $mail = new PHPMailer();
  2100. $body = $html_templete;
  2101. $mail->IsSMTP(); // telling the class to use SMTP
  2102. $mail->SMTPAuth = true; // enable SMTP authentication
  2103. //$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
  2104. $mail->Host = "smtp.exmail.qq.com"; // sets GMAIL as the SMTP server
  2105. //$mail->Port = 465; // set the SMTP port for the GMAIL server
  2106. //$mail->CharSet = "UTF8";
  2107. $mail->Username = "websupport@smartcost.com.cn"; // GMAIL username
  2108. $mail->Password = "smartcost2010"; // GMAIL password
  2109. $mail->From = "websupport@smartcost.com.cn";
  2110. $mail->FromName = "=?UTF-8?B?" . base64_encode('纵横知道·问答') . "?=";
  2111. $mail->Subject = $subject;
  2112. $mail->MsgHTML($body);
  2113. $mail->AddAddress($toemail);
  2114. $mail->Send();
  2115. }
  2116. /**
  2117. * 实现接口
  2118. * (non-PHPdoc)
  2119. * @see BaseLogic::format_email_content()
  2120. */
  2121. protected function format_email_content($html_templete, $templete_name, $postArray = 0, $user = 0,$v_oid) {
  2122. if ($templete_name == "RECHARGE_SUCCESS") { //纵横通行帐号提醒您:您的帐号成功充值了一笔金额
  2123. $str = str_replace ( "%username%",$user[0]['username'] , $html_templete );
  2124. $str = str_replace ( "%price%",$postArray , $str );
  2125. $str = str_replace ( "%oder%", $v_oid, $str );
  2126. $str = str_replace ( "%time%", date('Y-m-d H:i:s', time()), $str );
  2127. $result ['templete'] = $str;
  2128. $result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横通行帐号提醒您:您的帐号成功充值了一笔金额' ) . "?=";
  2129. $result ['toemail'] = $user [0]['useremail'];
  2130. return $result;
  2131. }
  2132. }
  2133. /**
  2134. * ajax短信验证码调用接口
  2135. */
  2136. public function checkSms(){
  2137. if(isset($_POST['zhmobile'])){
  2138. $mobile = trim($_POST['zhmobile']);
  2139. }else{
  2140. exit(json_encode(array('code' => -1, 'msg' => '请输入手机号')));
  2141. }
  2142. if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){
  2143. Doo::loadModel('users');
  2144. $user = new Users();
  2145. $checkuser = $user->getOne(array('where' => 'mobile='.$mobile, 'asArray' => true));
  2146. if(!empty($checkuser)){
  2147. exit(json_encode(
  2148. array('code' => -1, 'msg' => '该手机号码已被注册!')
  2149. ));
  2150. }
  2151. Doo::loadModel('mobilecode');
  2152. $mobilecode = new mobilecode();
  2153. $code = $this->getRandomCheckCode();
  2154. $now = time();
  2155. $checkresult = $mobilecode->find(array('where' => 'mobile='.$mobile, 'desc' => 'id', 'limit' => 1,'asArray' => true));
  2156. if(!empty($checkresult)){
  2157. $old = $checkresult['time'];
  2158. if($now-$old >= 60){
  2159. $sendresult = $this->sendSms($mobile,$code);
  2160. // $sendresult = true;
  2161. if($sendresult){
  2162. $mobilecode->mobile = $mobile;
  2163. $mobilecode->code = $code;
  2164. $mobilecode->time = $now;
  2165. $mobilecode->insert();
  2166. exit(json_encode(
  2167. array('code' => 1, 'msg' => '发送成功')
  2168. ));
  2169. }else{
  2170. exit(json_encode(
  2171. array('code' => -1, 'msg'=> $this->errorMsg)
  2172. ));
  2173. }
  2174. }else{
  2175. exit(json_encode(
  2176. array('code' => -1, 'msg' => '60s内无法再次发送验证码')
  2177. ));
  2178. }
  2179. }else{
  2180. $sendresult = $this->sendSms($mobile,$code);
  2181. // $sendresult = true;
  2182. if($sendresult){
  2183. $mobilecode->mobile = $mobile;
  2184. $mobilecode->code = $code;
  2185. $mobilecode->time = $now;
  2186. $mobilecode->insert();
  2187. exit(json_encode(
  2188. array('code' => 1, 'msg' => '发送成功')
  2189. ));
  2190. }else{
  2191. exit(json_encode(
  2192. array('code' => -1, 'msg'=> $this->errorMsg)
  2193. ));
  2194. }
  2195. }
  2196. }else{
  2197. exit(json_encode(
  2198. array('code' => -1, 'msg' => '请正确填写您的手机号码')
  2199. ));
  2200. }
  2201. }
  2202. /**
  2203. * ajax短信修改密码验证码调用接口
  2204. */
  2205. function chpwdsms(){
  2206. if(isset($_POST['zhmobile'])){
  2207. $mobile = trim($_POST['zhmobile']);
  2208. }else{
  2209. exit(json_encode(array('code' => -1, 'msg' => '请输入手机号')));
  2210. }
  2211. if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){
  2212. Doo::loadModel('mobilecode');
  2213. $mobilecode = new mobilecode();
  2214. $code = $this->getRandomCheckCode();
  2215. $now = time();
  2216. $checkresult = $mobilecode->find(array('where' => 'mobile='.$mobile, 'desc' => 'id', 'limit' => 1,'asArray' => true));
  2217. if(!empty($checkresult)){
  2218. $old = $checkresult['time'];
  2219. if($now-$old >= 60){
  2220. $sendresult = $this->sendSms($mobile,$code);
  2221. // $sendresult = true;
  2222. if($sendresult){
  2223. $mobilecode->mobile = $mobile;
  2224. $mobilecode->code = $code;
  2225. $mobilecode->time = $now;
  2226. $mobilecode->insert();
  2227. exit(json_encode(
  2228. array('code' => 1, 'msg' => '发送成功')
  2229. ));
  2230. }else{
  2231. exit(json_encode(
  2232. array('code' => -1, 'msg'=> $this->errorMsg)
  2233. ));
  2234. }
  2235. }else{
  2236. exit(json_encode(
  2237. array('code' => -1, 'msg' => '60s内无法再次发送验证码')
  2238. ));
  2239. }
  2240. }else{
  2241. $sendresult = $this->sendSms($mobile,$code);
  2242. // $sendresult = true;
  2243. if($sendresult){
  2244. $mobilecode->mobile = $mobile;
  2245. $mobilecode->code = $code;
  2246. $mobilecode->time = $now;
  2247. $mobilecode->insert();
  2248. exit(json_encode(
  2249. array('code' => 1, 'msg' => '发送成功')
  2250. ));
  2251. }else{
  2252. exit(json_encode(
  2253. array('code' => -1, 'msg'=> $this->errorMsg)
  2254. ));
  2255. }
  2256. }
  2257. }else{
  2258. exit(json_encode(
  2259. array('code' => -1, 'msg' => '请正确填写您的手机号码')
  2260. ));
  2261. }
  2262. }
  2263. function checkgetpwdsms(){
  2264. if(isset($_POST['zhmobile'])){
  2265. $mobile = trim($_POST['zhmobile']);
  2266. }else{
  2267. exit(json_encode(array('code' => -1, 'msg' => '请输入手机号')));
  2268. }
  2269. if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){
  2270. Doo::loadModel('users');
  2271. $user = new Users();
  2272. $checkuser = $user->getOne(array('where' => 'mobile='.$mobile, 'asArray' => true));
  2273. if(empty($checkuser)){
  2274. exit(json_encode(
  2275. array('code' => -1, 'msg' => '该手机号码未在纵横通行账号注册!')
  2276. ));
  2277. }
  2278. Doo::loadModel('mobilecode');
  2279. $mobilecode = new mobilecode();
  2280. $code = $this->getRandomCheckCode();
  2281. $now = time();
  2282. $checkresult = $mobilecode->find(array('where' => 'mobile='.$mobile, 'desc' => 'id', 'limit' => 1,'asArray' => true));
  2283. if(!empty($checkresult)){
  2284. $old = $checkresult['time'];
  2285. if($now-$old >= 60){
  2286. $sendresult = $this->sendSms($mobile,$code);
  2287. // $sendresult = true;
  2288. if($sendresult){
  2289. $mobilecode->mobile = $mobile;
  2290. $mobilecode->code = $code;
  2291. $mobilecode->time = $now;
  2292. $mobilecode->insert();
  2293. exit(json_encode(
  2294. array('code' => 1, 'msg' => '发送成功')
  2295. ));
  2296. }else{
  2297. exit(json_encode(
  2298. array('code' => -1, 'msg'=> $this->errorMsg)
  2299. ));
  2300. }
  2301. }else{
  2302. exit(json_encode(
  2303. array('code' => -1, 'msg' => '60s内无法再次发送验证码')
  2304. ));
  2305. }
  2306. }else{
  2307. $sendresult = $this->sendSms($mobile,$code);
  2308. // $sendresult = true;
  2309. if($sendresult){
  2310. $mobilecode->mobile = $mobile;
  2311. $mobilecode->code = $code;
  2312. $mobilecode->time = $now;
  2313. $mobilecode->insert();
  2314. exit(json_encode(
  2315. array('code' => 1, 'msg' => '发送成功')
  2316. ));
  2317. }else{
  2318. exit(json_encode(
  2319. array('code' => -1, 'msg'=> $this->errorMsg)
  2320. ));
  2321. }
  2322. }
  2323. }else{
  2324. exit(json_encode(
  2325. array('code' => -1, 'msg' => '请正确填写您的手机号码')
  2326. ));
  2327. }
  2328. }
  2329. /**
  2330. * 实现短信验证码接口
  2331. *
  2332. */
  2333. protected function sendSms($number,$code){
  2334. $send = array(
  2335. 'apikey' => 'fb5ef483e44b9556512a9febef376051',
  2336. 'mobile' => $number,
  2337. 'text' => '【纵横通行账号】您的验证码是'.$code.',15分钟内有效。'
  2338. );
  2339. $data = http_build_query($send);
  2340. $res = json_decode($this->_httpClient($data));
  2341. $resArr = $this->objectToArray($res);
  2342. if (!empty($resArr) && $resArr["code"] == 0) return true;
  2343. else {
  2344. if (empty($this->errorMsg)) $this->errorMsg = isset($resArr["msg"]) ? $resArr["msg"] : '未知错误';
  2345. return false;
  2346. }
  2347. }
  2348. //对象转数组,使用get_object_vars返回对象属性组成的数组
  2349. function objectToArray($array){
  2350. if(is_object($array)) {
  2351. $array = (array)$array;
  2352. } if(is_array($array)) {
  2353. foreach($array as $key=>$value) {
  2354. $array[$key] = $this->objectToArray($value);
  2355. }
  2356. }
  2357. return $array;
  2358. }
  2359. /**
  2360. * POST方式访问短信接口
  2361. * @param string $data
  2362. * @return mixed
  2363. */
  2364. private function _httpClient($data) {
  2365. $sms_api_url = 'http://sms.haotingyun.com/v2/sms/single_send.json';
  2366. try {
  2367. $ch = curl_init();
  2368. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
  2369. curl_setopt($ch, CURLOPT_URL,$sms_api_url);
  2370. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2371. curl_setopt($ch, CURLOPT_POST, 1);
  2372. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  2373. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2374. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  2375. $res = curl_exec($ch);
  2376. curl_close($ch);
  2377. return $res;
  2378. } catch (Exception $e) {
  2379. $this->errorMsg = $e->getMessage();
  2380. return false;
  2381. }
  2382. }
  2383. /**
  2384. * 随机生成验证码
  2385. */
  2386. function getRandomCheckCode() {
  2387. $chars = '0123456789';
  2388. mt_srand((double)microtime()*1000000*getmypid());
  2389. $CheckCode="";
  2390. while(strlen($CheckCode)<6)
  2391. $CheckCode.=substr($chars,(mt_rand()%strlen($chars)),1);
  2392. return $CheckCode;
  2393. }
  2394. // private static function isUserActive($uid) {
  2395. // Doo::loadModel('userswitch');
  2396. // $userswitch = new UserSwitch();
  2397. // return $userswitch->checkUserStatus($uid);
  2398. // }
  2399. }
  2400. ?>