refund.ctrl.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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()->classs('uploadedfile');
  9. $dos = array('save_setting', 'display');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. permission_check_account_user('profile_payment_refund', true, 'wxapp');
  12. if ($do == 'display') {
  13. $setting = uni_setting_load('payment', $_W['uniacid']);
  14. $setting = $setting['payment'];
  15. if (empty($setting['wechat_refund'])) {
  16. $setting['wechat_refund'] = array('switch' => 0, 'key' => '', 'cert' => '');
  17. }
  18. $has_cert = !empty($setting['wechat_refund']['cert']); $has_key = !empty($setting['wechat_refund']['key']); $open_or_close = !empty($setting['wechat_refund']['switch']);
  19. }
  20. if ($do == 'save_setting') {
  21. $type = $_GPC['type'];
  22. $is_open = $_GPC['switch'] == '1' ? 1 : 0;
  23. $setting = uni_setting_load('payment', $_W['uniacid']);
  24. $pay_setting = $setting['payment'];
  25. $files = UploadedFile::createFromGlobal();
  26. $cert = isset($files['cert']) ? $files['cert'] : null; $private_key = isset($files['key']) ? $files['key'] : null; $cert_content = $pay_setting['wechat_refund']['cert']; $private_key_content = $pay_setting['wechat_refund']['key']; $open_or_close = !empty($pay_setting['wechat_refund']['switch']);
  27. if($cert && $cert->isOk()) { $cert_content = $cert->getContent();
  28. $cert_content = authcode($cert_content, 'ENCODE');
  29. }
  30. if($private_key && $private_key->isOk()) { $key_content = $private_key->getContent();
  31. $private_key_content = authcode($key_content, 'ENCODE');
  32. }
  33. if($is_open) {
  34. if(! $cert_content) {
  35. itoast('请上传apiclient_cert.pem证书', '', 'info');
  36. }
  37. if(! $private_key_content) {
  38. itoast ('请上传apiclient_key.pem证书', '', 'info');
  39. }
  40. }
  41. $pay_setting['wechat_refund'] = array('cert'=>$cert_content,
  42. 'key'=>$private_key_content, 'switch'=>$is_open, 'version'=>1);
  43. uni_setting_save('payment', $pay_setting);
  44. itoast('设置成功', '', 'success');
  45. }
  46. template('wxapp/refund');