site.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class CoreModuleSite extends WeModuleSite {
  8. public function doMobilePaymethod() {
  9. global $_W, $_GPC;
  10. $params = array(
  11. 'fee' => floatval($_GPC['fee']),
  12. 'tid' => safe_gpc_string($_GPC['tid']),
  13. 'module' => safe_gpc_string($_GPC['module']),
  14. );
  15. if (empty($params['tid']) || empty($params['fee']) || empty($params['module'])) {
  16. message(error(1, '支付参数不完整'));
  17. }
  18. if ($params['fee'] <= 0) {
  19. $notify_params = array(
  20. 'form' => 'return',
  21. 'result' => 'success',
  22. 'type' => '',
  23. 'tid' => $params['tid'],
  24. );
  25. $site = WeUtility::createModuleSite($params['module']);
  26. $method = 'payResult';
  27. if (method_exists($site, $method)) {
  28. $site->$method($notify_params);
  29. message(error(-1, '支付成功'));
  30. }
  31. }
  32. $log = table('core_paylog')
  33. ->searWithUniacid($_W['uniacid'])
  34. ->SearWithModule($params['module'])
  35. ->searWithTid($params['tid'])
  36. ->get();
  37. if (empty($log)) {
  38. $log = array(
  39. 'uniacid' => $_W['uniacid'],
  40. 'acid' => $_W['acid'],
  41. 'openid' => $_W['member']['uid'],
  42. 'module' => $params['module'],
  43. 'tid' => $params['tid'],
  44. 'fee' => $params['fee'],
  45. 'card_fee' => $params['fee'],
  46. 'status' => '0',
  47. 'is_usecard' => '0',
  48. );
  49. table('core_paylog')->fill($log)->save();
  50. }
  51. if ('1' == $log['status']) {
  52. message(error(1, '订单已经支付'));
  53. }
  54. $setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
  55. if (!is_array($setting['payment'])) {
  56. message(error(1, '暂无有效支付方式'));
  57. }
  58. $pay = $setting['payment'];
  59. if (empty($_W['member']['uid'])) {
  60. $pay['credit']['switch'] = false;
  61. }
  62. if (!empty($pay['credit']['switch'])) {
  63. $credtis = mc_credit_fetch($_W['member']['uid']);
  64. }
  65. include $this->template('pay');
  66. }
  67. public function doMobilePay() {
  68. global $_W, $_GPC;
  69. $moduels = uni_modules();
  70. $params = $_POST;
  71. if (empty($params) || !array_key_exists($params['module'], $moduels)) {
  72. message(error(1, '模块不存在'), '', 'ajax', true);
  73. }
  74. $setting = uni_setting($_W['uniacid'], 'payment');
  75. $dos = array();
  76. if (!empty($setting['payment']['credit']['pay_switch'])) {
  77. $dos[] = 'credit';
  78. }
  79. if (!empty($setting['payment']['alipay']['pay_switch'])) {
  80. $dos[] = 'alipay';
  81. }
  82. if (!empty($setting['payment']['wechat']['pay_switch'])) {
  83. $dos[] = 'wechat';
  84. }
  85. if (!empty($setting['payment']['delivery']['pay_switch'])) {
  86. $dos[] = 'delivery';
  87. }
  88. if (!empty($setting['payment']['unionpay']['pay_switch'])) {
  89. $dos[] = 'unionpay';
  90. }
  91. if (!empty($setting['payment']['baifubao']['pay_switch'])) {
  92. $dos[] = 'baifubao';
  93. }
  94. $type = in_array($params['method'], $dos) ? $params['method'] : '';
  95. if (empty($type)) {
  96. message(error(1, '暂无有效支付方式,请联系商家'), '', 'ajax', true);
  97. }
  98. $moduleid = table('modules')
  99. ->where(array('name' => $params['module']))
  100. ->getcolumn('mid');
  101. $moduleid = empty($moduleid) ? '000000' : sprintf('%06d', $moduleid);
  102. $uniontid = date('YmdHis') . $moduleid . random(8, 1);
  103. $paylog = table('core_paylog')
  104. ->where(array('uniacid' => $uniacid))
  105. ->searchWithModule($params['module'])
  106. ->searchWithTid($params['tid'])
  107. ->get();
  108. if (empty($paylog)) {
  109. $paylog = array(
  110. 'uniacid' => $_W['uniacid'],
  111. 'acid' => $_W['acid'],
  112. 'openid' => $_W['member']['uid'],
  113. 'type' => $type,
  114. 'module' => $params['module'],
  115. 'tid' => $params['tid'],
  116. 'uniontid' => $uniontid,
  117. 'fee' => $params['fee'],
  118. 'card_fee' => $params['fee'],
  119. 'status' => '0',
  120. 'is_usecard' => '0',
  121. );
  122. table('core_paylog')->fill($paylog)->save();
  123. $paylog['plid'] = pdo_insertid();
  124. }
  125. if (!empty($paylog) && '0' != $paylog['status']) {
  126. message(error(1, '这个订单已经支付成功, 不需要重复支付.'), '', 'ajax', true);
  127. }
  128. if (!empty($paylog) && empty($paylog['uniontid'])) {
  129. table('core_paylog')
  130. ->where(array('plid' => $paylog['plid']))
  131. ->fill(array('uniontid' => $uniontid))
  132. ->save();
  133. }
  134. $paylog['title'] = $params['title'];
  135. if (intval($_GPC['iswxapp'])) {
  136. message(error(2, $_W['siteroot'] . "app/index.php?i={$_W['uniacid']}&c=wxapp&a=home&do=go_paycenter&title={$params['title']}&plid={$paylog['plid']}"), '', 'ajax', true);
  137. }
  138. if ('wechat' == $params['method']) {
  139. if (!empty($params['goods_tag'])) {
  140. $paylog['goods_tag'] = $params['goods_tag'];
  141. }
  142. return $this->doMobilePayWechat($paylog);
  143. } elseif ('alipay' == $params['method']) {
  144. return $this->doMobilePayAlipay($paylog);
  145. } else {
  146. $params['tid'] = $paylog['plid'];
  147. $sl = base64_encode(json_encode($params));
  148. $auth = sha1($sl . $_W['uniacid'] . $_W['config']['setting']['authkey']);
  149. message(error(0, $_W['siteroot'] . "/payment/{$type}/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}"), '', 'ajax', true);
  150. exit();
  151. }
  152. }
  153. private function doMobilePayWechat($paylog = array()) {
  154. global $_W;
  155. load()->model('payment');
  156. table('core_paylog')
  157. ->where(array('plid' => $paylog['plid']))
  158. ->fill(array(
  159. 'openid' => $_W['openid'],
  160. 'tag' => iserializer(array('acid' => $_W['acid'], 'uid' => $_W['member']['uid'])),
  161. ))
  162. ->save();
  163. $_W['uniacid'] = $paylog['uniacid'];
  164. $setting = uni_setting($_W['uniacid'], array('payment'));
  165. $wechat_payment = $setting['payment']['wechat'];
  166. $account = table('account_wechats')
  167. ->where(array('acid' => $wechat_payment['account']))
  168. ->get();
  169. $wechat_payment['appid'] = $account['key'];
  170. $wechat_payment['secret'] = $account['secret'];
  171. $params = array(
  172. 'tid' => $paylog['tid'],
  173. 'fee' => $paylog['card_fee'],
  174. 'user' => $paylog['openid'],
  175. 'title' => urldecode($paylog['title']),
  176. 'uniontid' => $paylog['uniontid'],
  177. 'goods_tag' => empty($paylog['goods_tag']) ? '' : $paylog['goods_tag'],
  178. );
  179. if (PAYMENT_WECHAT_TYPE_SERVICE == intval($wechat_payment['switch']) || PAYMENT_WECHAT_TYPE_BORROW == intval($wechat_payment['switch'])) {
  180. if (PAYMENT_WECHAT_TYPE_SERVICE == intval($wechat_payment['switch'])) {
  181. $wechat_payment['sub_appid'] = $wechat_payment['appid'];
  182. }
  183. $params['tid'] = $paylog['plid'];
  184. $params['title'] = urlencode($params['title']);
  185. $sl = base64_encode(json_encode($params));
  186. $auth = sha1($sl . $paylog['uniacid'] . $_W['config']['setting']['authkey']);
  187. $callback = urlencode($_W['siteroot'] . "payment/wechat/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}");
  188. $proxy_pay_account = payment_proxy_pay_account();
  189. if (!is_error($proxy_pay_account)) {
  190. $forward = $proxy_pay_account->getOauthCodeUrl($callback, 'we7sid-' . $_W['session_id']);
  191. message(error(2, $forward . '##auto'), $forward, 'ajax');
  192. exit;
  193. }
  194. } else {
  195. unset($wechat_payment['sub_mch_id']);
  196. $wechat_payment_params = wechat_build($params, $wechat_payment);
  197. }
  198. if (is_error($wechat_payment_params)) {
  199. message($wechat_payment_params, '', 'ajax', true);
  200. } else {
  201. message(error(0, $wechat_payment_params), '', 'ajax', true);
  202. }
  203. }
  204. private function doMobilePayAlipay($paylog = array()) {
  205. global $_W;
  206. load()->model('payment');
  207. load()->func('communication');
  208. $_W['uniacid'] = $paylog['uniacid'];
  209. $setting = uni_setting($_W['uniacid'], array('payment'));
  210. $params = array(
  211. 'tid' => $paylog['tid'],
  212. 'fee' => $paylog['card_fee'],
  213. 'user' => $paylog['openid'],
  214. 'title' => urldecode($paylog['title']),
  215. 'uniontid' => $paylog['uniontid'],
  216. );
  217. $alipay_payment_params = alipay_build($params, $setting['payment']['alipay']);
  218. if ($alipay_payment_params['url']) {
  219. message(error(0, $alipay_payment_params['url']), '', 'ajax', true);
  220. exit();
  221. }
  222. }
  223. public function doMobileDetail() {
  224. global $_W, $_GPC;
  225. $id = intval($_GPC['id']);
  226. $row = table('news_reply')->getById($id);
  227. $createtime = $row['createtime'];
  228. if (!empty($row['url'])) {
  229. header('Location: ' . $row['url']);
  230. exit;
  231. }
  232. if (!empty($row['media_id']) && 0 != intval($row['media_id'])) {
  233. $row = table('wechat_news')
  234. ->where(array(
  235. 'attach_id' => $row['media_id'],
  236. 'displayorder' => $row['displayorder']
  237. ))
  238. ->get();
  239. $row['createtime'] = $createtime;
  240. if (!empty($row['content_source_url'])) {
  241. header('Location: ' . $row['content_source_url']);
  242. exit;
  243. }
  244. }
  245. $row = istripslashes($row);
  246. $title = $row['title'];
  247. if ('android' == $_W['os'] && 'wechat' == $_W['container'] && $_W['account']['account']) {
  248. $subscribeurl = "weixin://profile/{$_W['account']['account']}";
  249. } else {
  250. $subscribeurl = table('account_wechats')
  251. ->where(array('uniacid' => intval($_W['uniacid'])))
  252. ->getcolumn('subscribeurl');
  253. }
  254. include $this->template('detail');
  255. }
  256. }