国内流行的内容管理系统(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.

229 lines
8.5KB

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