notify_invite.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: notify_invite.php 34251 2013-11-25 03:10:11Z nemohou $
  7. */
  8. define('IN_API', true);
  9. define('CURSCRIPT', 'api');
  10. define('DISABLEXSSCHECK', true);
  11. require '../../source/class/class_core.php';
  12. require '../../source/function/function_forum.php';
  13. $discuz = C::app();
  14. $discuz->init();
  15. $apitype = empty($_GET['attach']) || !preg_match('/^[a-z0-9]+$/i', $_GET['attach']) ? 'alipay' : $_GET['attach'];
  16. require_once DISCUZ_ROOT.'./api/trade/api_'.$apitype.'.php';
  17. $PHP_SELF = $_SERVER['PHP_SELF'];
  18. $_G['siteurl'] = dhtmlspecialchars('http://'.$_SERVER['HTTP_HOST'].preg_replace("/\/+(api\/trade)?\/*$/i", '', substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'))).'/');
  19. $notifydata = trade_notifycheck('invite');
  20. if($notifydata['validator']) {
  21. $orderid = $notifydata['order_no'];
  22. $postprice = $notifydata['price'];
  23. $order = C::t('forum_order')->fetch($orderid);
  24. if($order && floatval($postprice) == floatval($order['price']) && ($apitype == 'tenpay' || $_G['setting']['ec_account'] == $_REQUEST['seller_email'])) {
  25. if($order['status'] == 1) {
  26. C::t('forum_order')->update($orderid, array('status' => '2', 'buyer' => "$notifydata[trade_no]\t$apitype", 'confirmdate' => $_G['timestamp']));
  27. $codes = $codetext = array();
  28. $dateline = TIMESTAMP;
  29. for($i=0; $i<$order['amount']; $i++) {
  30. $code = strtolower(random(6));
  31. $codetext[] = $code;
  32. $codes[] = "('0', '$code', '$dateline', '".($_G['group']['maxinviteday']?($_G['timestamp']+$_G['group']['maxinviteday']*24*3600):$_G['timestamp']+86400*10)."', '$order[email]', '$_G[clientip]', '$orderid')";
  33. $invitedata = array(
  34. 'uid' => 0,
  35. 'code' => $code,
  36. 'dateline' => $dateline,
  37. 'endtime' => $_G['group']['maxinviteday'] ? ($_G['timestamp']+$_G['group']['maxinviteday']*24*3600) : $_G['timestamp']+86400*10,
  38. 'email' => $order['email'],
  39. 'inviteip' => $_G['clientip'],
  40. 'orderid' => $orderid
  41. );
  42. C::t('common_invite')->insert($invitedata);
  43. }
  44. C::t('forum_order')->delete_by_submitdate($_G['timestamp']-60*86400);
  45. $submitdate = dgmdate($order['submitdate']);
  46. $confirmdate = dgmdate(TIMESTAMP);
  47. if(!function_exists('sendmail')) {
  48. include libfile('function/mail');
  49. }
  50. $add_member_subject = $_G['setting']['bbname'].' - '.lang('forum/misc', 'invite_payment');
  51. $add_member_message = lang('email', 'invite_payment_email_message', array(
  52. 'orderid' => $order['orderid'],
  53. 'codetext' => implode('<br />', $codetext),
  54. 'siteurl' => $_G['siteurl'],
  55. 'bbname' => $_G['setting']['bbname'],
  56. ));
  57. if(!sendmail($order['email'], $add_member_subject, $add_member_message)) {
  58. runlog('sendmail', "$order[email] sendmail failed.");
  59. }
  60. }
  61. }
  62. }
  63. if($notifydata['location']) {
  64. if($apitype == 'tenpay') {
  65. echo <<<EOS
  66. <meta name="TENCENT_ONLINE_PAYMENT" content="China TENCENT">
  67. <html>
  68. <body>
  69. <script language="javascript" type="text/javascript">
  70. window.location.href='$_G[siteurl]misc.php?mod=buyinvitecode&action=paysucceed&orderid=$orderid';
  71. </script>
  72. </body>
  73. </html>
  74. EOS;
  75. } else {
  76. dheader('location: '.$_G['siteurl'].'misc.php?mod=buyinvitecode&action=paysucceed&orderid='.$orderid);
  77. }
  78. } else {
  79. exit($notifydata['notify']);
  80. }
  81. ?>