国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
9.0KB

  1. <?php
  2. /**
  3. * 支付接口
  4. *
  5. * @version $Id: sys_info_mark.php 1 22:28 2010年7月20日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__) . "/config.php");
  12. require_once(DEDEINC . '/datalistcp.class.php');
  13. CheckPurview('sys_Data');
  14. $dopost = (empty($dopost)) ? '' : $dopost;
  15. $pid = (empty($pid)) ? 0 : intval($pid);
  16. /*
  17. 下面数数组格式的例子:
  18. */
  19. //一个简单的[数组<->表单]解析类
  20. /*数组结构应该为:
  21. array(
  22. [name]=>array(
  23. [title]=>'当前表单项的名称',
  24. [type]=>'text|select',
  25. [description]=>'表单内容的介绍说明'
  26. [iterm]=>'1:使用标准双接口,使用担保交易接口', //如果含有":",则前面为value值,后面为显示内容
  27. [value]=>'使用担保交易接口',
  28. ),
  29. ...
  30. )
  31. 使用方法:
  32. 将上述的格式传入到数组中去,然后进行解析:
  33. 1.声明类,并创建数组
  34. $af = new Array2form($config);
  35. 2.设置一个表单模板(可选,如果不设置载入默认)
  36. $af->SetDefaultTpl($templets); $templets:为一个底册模板文件
  37. 表单模板格式为:
  38. <p>~title~:~form~<small>~description~</small></p>
  39. 3.获取特定项目表单
  40. $af->GetIterm('alipay', 1) //1.表示获取一个默认模板下的完整表单,2.仅获取一个表单项
  41. 4.获取所有表单内容
  42. $af->GetAll() //获取表单所有解析后的内容
  43. */
  44. class Array2form
  45. {
  46. var $FormArray = array();
  47. var $ArrFromTPL = '';
  48. function __construct($formarray = array())
  49. {
  50. if (count($formarray) > 1) {
  51. $this->FormArray = $formarray;
  52. //var_dump($this->FormArray);
  53. $this->SetDefaultTpl();
  54. }
  55. }
  56. //析构函数,兼容PHP4
  57. /*
  58. function Array2form($formarray = array())
  59. {
  60. $this->__construct($formarray);
  61. }
  62. */
  63. //获取一个特定项目的表单
  64. function GetIterm($itermid = '', $itermtype = 1)
  65. {
  66. $reval = $reval_form = $reval_title = $reval_des = $myformItem = '';
  67. if (is_array($this->FormArray)) {
  68. foreach ($this->FormArray as $key => $val) {
  69. if ($key == $itermid) {
  70. $reval_title = $val['title'];
  71. $reval_des = $val['description'];
  72. $reval_form = $this->GetForm($key, $val, $val['type']);
  73. //进行模板标签替换
  74. if ($itermtype == 1)
  75. $reval = preg_replace(
  76. array("/~title~/", "/~form~/", "/~description~/"),
  77. array($reval_title, $reval_form, $reval_des),
  78. $this->ArrFromTPL
  79. );
  80. else return $reval_form;
  81. }
  82. }
  83. } else {
  84. return FALSE;
  85. }
  86. return empty($reval) ? '' : $reval;
  87. }
  88. function GetForm($key, $formarry = array(), $formtype = 'text')
  89. {
  90. switch ($formtype) {
  91. case 'text':
  92. //生成文本编辑框
  93. $valstr = (empty($formarry['value'])) ? "value=''" : "value='{$formarry['value']}'";
  94. $reval_form = "<input type='text' name='{$key}' id='{$key}' style='width:300px' class='text'{$valstr}>";
  95. break;
  96. case 'select':
  97. //生成选择框
  98. $reval_title = $formarry['title'];
  99. $items = explode(',', $formarry['iterm']);
  100. $reval_form = "<select name='{$key}' class='text'>";
  101. if (is_array($items)) {
  102. foreach ($items as $v) {
  103. $v = trim($v);
  104. if ($v == '') continue;
  105. //统一将中文冒号转为英文
  106. $v = str_replace(":", ":", $v);
  107. if (preg_match("/[\:]/", $v)) {
  108. list($value, $name) = preg_split('#:#', $v);
  109. $reval_form .= ($formarry['value'] == $value) ? "<option value='$value' selected>$name</option>\r\n" : "<option value='$value'>$name</option>\r\n";
  110. } else {
  111. $reval_form .= ($formarry['value'] == $v) ? "<option value='$v' selected>$v</option>\r\n" : "<option value='$v'>$v</option>\r\n";
  112. }
  113. }
  114. }
  115. $reval_form .= "</select>\r\n";
  116. break;
  117. }
  118. return $reval_form;
  119. }
  120. //获取所有的表单内容
  121. function GetAll()
  122. {
  123. $reval = empty($reval) ? '' : $reval;
  124. if (is_array($this->FormArray)) {
  125. foreach ($this->FormArray as $key => $val) {
  126. $reval .= $this->GetIterm($key);
  127. }
  128. return $reval;
  129. } else {
  130. return FALSE;
  131. }
  132. }
  133. //获取一个特定项目的表单
  134. function SetDefaultTpl($tplname = '')
  135. {
  136. if (empty($tplname)) {
  137. $this->ArrFromTPL = '<p>~title~:~form~<small>~description~</small></p>';
  138. } else {
  139. if (file_exists($tplname)) $this->ArrFromTPL = file_get_contents($tplname);
  140. else $this->ArrFromTPL = $tplname;
  141. }
  142. }
  143. }
  144. $tplstring = "
  145. <tr>
  146. <td height='25' align='center'>~title~:</td>
  147. <td>~form~ <small>~description~</small></td>
  148. </tr>
  149. ";
  150. //安装支付接口
  151. if ($dopost == 'install') {
  152. $row = $dsql->GetOne("SELECT * FROM `#@__payment` WHERE id='$pid'");
  153. if (is_array($row)) {
  154. if ($cfg_soft_lang == 'utf-8') {
  155. $config_row = AutoCharset(unserialize(utf82gb($row['config'])));
  156. } else if ($cfg_soft_lang == 'gb2312') {
  157. $config_row = unserialize($row['config']);
  158. }
  159. //print_r($config_row);exit;
  160. $af = new Array2form($config_row);
  161. $af->SetDefaultTpl($tplstring);
  162. $reval = $af->GetAll();
  163. }
  164. include DedeInclude('templets/sys_payment_install.htm');
  165. exit;
  166. }
  167. //配置支付接口
  168. else if ($dopost == 'config') {
  169. if ($pay_name == "" || $pay_desc == "" || $pay_fee == "") {
  170. ShowMsg("您有未填写的项目!", "-1");
  171. exit();
  172. }
  173. $row = $dsql->GetOne("SELECT * FROM `#@__payment` WHERE id='$pid'");
  174. if ($cfg_soft_lang == 'utf-8') {
  175. $config = AutoCharset(unserialize(utf82gb($row['config'])));
  176. } else if ($cfg_soft_lang == 'gb2312') {
  177. $config = unserialize($row['config']);
  178. }
  179. $payments = "'code' => '" . $row['code'] . "',";
  180. foreach ($config as $key => $v) {
  181. $config[$key]['value'] = ${$key};
  182. $payments .= "'" . $key . "' => '" . $config[$key]['value'] . "',";
  183. }
  184. $payments = substr($payments, 0, -1);
  185. $payment = "\$payment=array(" . $payments . ")";
  186. $configstr = "<" . "?php\r\n" . $payment . "\r\n?" . ">\r\n";
  187. if (!empty($payment)) {
  188. $m_file = DEDEDATA . "/payment/" . $row['code'] . ".php";
  189. $fp = fopen($m_file, "w") or die("写入文件 $safeconfigfile 失败,请检查权限!");
  190. fwrite($fp, $configstr);
  191. fclose($fp);
  192. }
  193. if ($cfg_soft_lang == 'utf-8') {
  194. $config = AutoCharset($config, 'utf-8', 'gb2312');
  195. $config = serialize($config);
  196. $config = gb2utf8($config);
  197. } else {
  198. $config = serialize($config);
  199. }
  200. $query = "UPDATE `#@__payment` SET name = '$pay_name',fee='$pay_fee',description='$pay_desc',config='$config',enabled='1' WHERE id='$pid'";
  201. $dsql->ExecuteNoneQuery($query);
  202. if ($pm == 'edit') $msg = "保存修改成功";
  203. else $msg = "安装成功!";
  204. ShowMsg($msg, "sys_payment.php");
  205. exit();
  206. }
  207. //删除支付接口
  208. else if ($dopost == 'uninstall') {
  209. $row = $dsql->GetOne("SELECT * FROM `#@__payment` WHERE id='$pid'");
  210. if ($cfg_soft_lang == 'utf-8') {
  211. $config = AutoCharset(unserialize(utf82gb($row['config'])));
  212. } else if ($cfg_soft_lang == 'gb2312') {
  213. $config = unserialize($row['config']);
  214. }
  215. foreach ($config as $key => $v) $config[$key]['value'] = "";
  216. if ($cfg_soft_lang == 'utf-8') {
  217. $config = AutoCharset($config, 'utf-8', 'gb2312');
  218. $config = serialize($config);
  219. $config = gb2utf8($config);
  220. } else {
  221. $config = serialize($config);
  222. }
  223. $query = "UPDATE `#@__payment` SET fee='',config='$config',enabled='0' WHERE id='$pid'";
  224. $dsql->ExecuteNoneQuery($query);
  225. //同时需要删除对应的缓存
  226. $m_file = DEDEDATA . "/payment/" . $row['code'] . ".php";
  227. @unlink($m_file);
  228. ShowMsg("删除成功!", "sys_payment.php");
  229. exit();
  230. }
  231. $sql = "SELECT * FROM `#@__payment` ORDER BY rank ASC";
  232. $dlist = new DataListCP();
  233. $dlist->SetTemplet(DEDEADMIN . "/templets/sys_payment.htm");
  234. $dlist->SetSource($sql);
  235. $dlist->display();