refund.ctrl.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. $dos = array('save_setting', 'display');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. permission_check_account_user('profile_payment_refund');
  12. if ($do == 'display') {
  13. $setting = uni_setting_load('payment', $_W['uniacid']);
  14. $setting = (array)$setting['payment'];
  15. if (empty($setting['wechat_refund'])) {
  16. $setting['wechat_refund'] = array('switch' => 0, 'key' => '', 'cert' => '');
  17. }
  18. if (empty($setting['ali_refund'])) {
  19. $setting['ali_refund'] = array('switch' => 0, 'private_key' => '');
  20. }
  21. }
  22. if ($do == 'save_setting') {
  23. $type = $_GPC['type'];
  24. $param = $_GPC['param'];
  25. $setting = uni_setting_load('payment', $_W['uniacid']);
  26. $pay_setting = (array)$setting['payment'];
  27. if ($type == 'wechat_refund') {
  28. if (empty($_FILES['cert']['tmp_name'])) {
  29. if (empty($setting['payment']['wechat_refund']['cert']) && $param['switch'] == 1) {
  30. itoast('请上传apiclient_cert.pem证书', '', 'info');
  31. }
  32. $param['cert'] = $setting['payment']['wechat_refund']['cert'];
  33. } else {
  34. $param['cert'] = file_get_contents($_FILES['cert']['tmp_name']);
  35. if (strexists($param['cert'], '<?php') || substr($param['cert'], 0, 27) != '-----BEGIN CERTIFICATE-----' || substr($param['cert'], -24, 23) != '---END CERTIFICATE-----') {
  36. itoast('apiclient_cert.pem证书内容不合法,请重新上传');
  37. }
  38. $param['cert'] = authcode($param['cert'], 'ENCODE');
  39. }
  40. if (empty($_FILES['key']['tmp_name'])) {
  41. if (empty($setting['payment']['wechat_refund']['key']) && $param['switch'] == 1) {
  42. itoast ('请上传apiclient_key.pem证书', '', 'info');
  43. }
  44. $param['key'] = $setting['payment']['wechat_refund']['key'];
  45. } else {
  46. $param['key'] = file_get_contents($_FILES['key']['tmp_name']);
  47. if (strexists($param['key'], '<?php') || substr($param['key'], 0, 27) != '-----BEGIN PRIVATE KEY-----' || substr($param['key'], -24, 23) != '---END PRIVATE KEY-----') {
  48. itoast('apiclient_key.pem证书内容不合法,请重新上传');
  49. }
  50. $param['key'] = authcode($param['key'], 'ENCODE');
  51. }
  52. } elseif ($type == 'ali_refund') {
  53. if (empty($_FILES['private_key']['tmp_name'])) {
  54. if (empty($setting['payment']['ali_refund']['private_key']) && $param['switch'] == 1) {
  55. itoast('请上传rsa_private_key.pem证书', '', 'info');
  56. }
  57. $param['private_key'] = $setting['payment']['ali_refund']['private_key'];
  58. } else {
  59. $param['private_key'] = file_get_contents($_FILES['private_key']['tmp_name']);
  60. if (strexists($param['private_key'], '<?php') || substr($param['private_key'], 0, 27) != '-----BEGIN RSA PRIVATE KEY-' || substr($param['private_key'], -24, 23) != 'ND RSA PRIVATE KEY-----') {
  61. itoast('rsa_private_key.pem证书内容不合法,请重新上传');
  62. }
  63. $param['private_key'] = authcode($param['private_key'], 'ENCODE');
  64. }
  65. }
  66. $pay_setting[$type] = $param;
  67. uni_setting_save('payment', $pay_setting);
  68. itoast('设置成功', '', 'success');
  69. }
  70. template('profile/refund');