人人商城

payment.ctrl.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. load()->model('payment');
  8. load()->model('account');
  9. load()->func('communication');
  10. $dos = array('save_setting', 'display', 'test_alipay', 'get_setting', 'switch', 'change_status');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. permission_check_account_user('profile_payment_pay');
  13. $_W['page']['title'] = '支付参数 - 公众号选项';
  14. if ($do == 'get_setting') {
  15. $pay_setting = payment_setting();
  16. iajax(0, $pay_setting, '');
  17. }
  18. if ($do == 'test_alipay') {
  19. $alipay = $_GPC['param'];
  20. $pay_data = array(
  21. 'uniacid' => $_W['uniacid'],
  22. 'acid' => $_W['acid'],
  23. 'uniontid' => date('Ymd', time()).time(),
  24. 'module' => 'system',
  25. 'fee' => '0.01',
  26. 'status' => 0,
  27. 'card_fee' => 0.01
  28. );
  29. $params = array();
  30. $params['tid'] = md5(uniqid());
  31. $params['user'] = '测试用户';
  32. $params['fee'] = '0.01';
  33. $params['title'] = '测试支付接口';
  34. $params['uniontid'] = $pay_data['uniontid'];
  35. $result = alipay_build($params, $alipay);
  36. iajax(0, $result['url'], '');
  37. }
  38. if ($do == 'save_setting') {
  39. $type = $_GPC['type'];
  40. $param = $_GPC['param'];
  41. $setting = uni_setting_load('payment', $_W['uniacid']);
  42. $pay_setting = $setting['payment'];
  43. if ($type == 'wechat_facilitator') {
  44. $param['switch'] = $param['switch'] == 'true' ? true : false;
  45. }
  46. if ($type == 'wechat') {
  47. $param['account'] = $_W['acid'];
  48. if ($param['switch'] == 1) {
  49. $param['signkey'] = $param['version'] == 2 ? trim($param['apikey']) : trim($param['signkey']);
  50. }
  51. }
  52. if ($type == 'unionpay') {
  53. $unionpay = $_GPC['unionpay'];
  54. $switch_status = ($unionpay['pay_switch'] || $unionpay['recharge_switch']) ? true : false;
  55. if ($switch_status && empty($_FILES['unionpay']['tmp_name']['signcertpath']) && !file_exists(IA_ROOT . '/attachment/unionpay/PM_'.$_W['uniacid'].'_acp.pfx')) {
  56. itoast('请上联银商户私钥证书.', referer(), 'error');
  57. }
  58. $param = array(
  59. 'merid' => $unionpay['merid'],
  60. 'signcertpwd' => $unionpay['signcertpwd']
  61. );
  62. if($switch_status && (empty($param['merid']) || empty($param['signcertpwd']))) {
  63. itoast('请输入完整的银联支付接口信息.', referer(), 'error');
  64. }
  65. if ($switch_status && empty($_FILES['unionpay']['tmp_name']['signcertpath']) && !file_exists(IA_ROOT . '/attachment/unionpay/PM_'.$_W['uniacid'].'_acp.pfx')) {
  66. itoast('请上传银联商户私钥证书.', referer(), 'error');
  67. }
  68. if ($switch_status && !empty($_FILES['unionpay']['tmp_name']['signcertpath'])) {
  69. load()->func('file');
  70. mkdirs(IA_ROOT . '/attachment/unionpay/');
  71. file_put_contents(IA_ROOT . '/attachment/unionpay/PM_'.$_W['uniacid'].'_acp.pfx', file_get_contents($_FILES['unionpay']['tmp_name']['signcertpath']));
  72. $public_rsa = '-----BEGIN CERTIFICATE-----
  73. MIIEIDCCAwigAwIBAgIFEDRVM3AwDQYJKoZIhvcNAQEFBQAwITELMAkGA1UEBhMC
  74. Q04xEjAQBgNVBAoTCUNGQ0EgT0NBMTAeFw0xNTEwMjcwOTA2MjlaFw0yMDEwMjIw
  75. OTU4MjJaMIGWMQswCQYDVQQGEwJjbjESMBAGA1UEChMJQ0ZDQSBPQ0ExMRYwFAYD
  76. VQQLEw1Mb2NhbCBSQSBPQ0ExMRQwEgYDVQQLEwtFbnRlcnByaXNlczFFMEMGA1UE
  77. Aww8MDQxQDgzMTAwMDAwMDAwODMwNDBA5Lit5Zu96ZO26IGU6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TaaWFd+cZ3P/zmIUskE/dAG0/HEvmOR6CGlM
  94. 55BFCVmJEufHtike3shu7lZGVm2adKNFFTqLoEFkfBO6Y/N6ViraBilcXjmWBJNE
  95. MFF/yA==
  96. -----END CERTIFICATE-----';
  97. file_put_contents(IA_ROOT . '/attachment/unionpay/UpopRsaCert.cer', trim($public_rsa));
  98. }
  99. }
  100. $pay_setting[$type] = $param;
  101. $payment = iserializer($pay_setting);
  102. uni_setting_save('payment', $payment);
  103. if ($type == 'wechat_facilitator') {
  104. cache_clean(cache_system_key('proxy_wechatpay_account:'));
  105. }
  106. iajax(0, '设置成功!', referer());
  107. }
  108. if ($do == 'change_status') {
  109. $types = array('unionpay', 'jueqiymf', 'alipay', 'baifubao', 'line', 'credit', 'delivery', 'mix', 'wechat');
  110. $type = in_array($_GPC['type'], $types) ? $_GPC['type'] : '';
  111. if (empty($type)) {
  112. iajax(-1, '参数错误!');
  113. }
  114. $param = $_GPC['param'];
  115. $setting = uni_setting_load('payment', $_W['uniacid']);
  116. $pay_setting = $setting['payment'];
  117. $setting_data = array(
  118. 'pay_switch' => $param['pay_switch'] == 'true' ? true : false,
  119. 'recharge_switch' => $param['recharge_switch'] == 'true' ? true : false,
  120. );
  121. if ($type == 'credit' || $type == 'delivery' || $type == 'mix') {
  122. $param['recharge_switch'] = false;
  123. }
  124. $pay_setting[$type]['pay_switch'] = $setting_data['pay_switch'];
  125. $pay_setting[$type]['recharge_switch'] = $setting_data['recharge_switch'];
  126. $payment = iserializer($pay_setting);
  127. uni_setting_save('payment', $payment);
  128. iajax(0, '设置成功!', referer());
  129. }
  130. if ($do == 'display' || $do == 'switch') {
  131. $proxy_wechatpay_account = account_wechatpay_proxy();
  132. $pay_setting = payment_setting();
  133. $accounts = array();
  134. $accounts[$_W['acid']] = array_elements(array('name', 'acid', 'key', 'secret', 'level'), $_W['account']);
  135. }
  136. if ($do == 'switch') {
  137. $payment_types = payment_types();
  138. if (empty($payment_types[$_GPC['type']])) {
  139. itoast('参数错误', url('profile/payment'), 'error');
  140. }
  141. }
  142. template('profile/payment');