Set.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Pay\Lib;
  3. use Dever;
  4. class Set
  5. {
  6. # 可以自定义token的key
  7. public function updateStatus_secure_api_token()
  8. {
  9. $project_id = Dever::input('pay_project_id');
  10. $info = Dever::db('pay/project')->one($project_id);
  11. if ($info) {
  12. return $info['key'];
  13. }
  14. return false;
  15. }
  16. # 带有安全验证的接口 需要传入dever_token,可以参考下边的test_order例子
  17. public function updateStatus_secure_api($param = array())
  18. {
  19. $send = $param ? $param : Dever::preInput('pay_');
  20. $tk_pic = $send['pay_tk_pic'];
  21. $tk_time = $send['pay_tk_time'];
  22. $tk_desc = $send['pay_tk_desc'];
  23. $order_id = $send['pay_order_id'];
  24. $account_id = $send['pay_account_id'];
  25. $status = $send['pay_status'];
  26. $uid = $send['pay_uid'];
  27. $cash = $send['pay_cash'];
  28. $project_id = Dever::load('pay/lib/core')->checkOrder($order_id);
  29. if ($project_id) {
  30. $order = array();
  31. $order['account_id'] = $account_id;
  32. } else {
  33. $order = Dever::db('pay/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  34. if ($order && $order['cash']) {
  35. $cash = $order['cash'];
  36. }
  37. }
  38. if ($order) {
  39. if ($status == 5) {
  40. $pay = Dever::db('pay/account')->one($order['account_id']);
  41. $method = '\\Pay\\Lib\\' . ucwords($pay['type']);
  42. $method = new $method($pay);
  43. $result = $method->refund($order_id, $cash);
  44. }
  45. if (isset($order['id'])) {
  46. $update['where_id'] = $order['id'];
  47. $update['status'] = $status;
  48. $update['tk_pic'] = $tk_pic;
  49. $update['tk_time'] = $tk_time;
  50. $update['tk_desc'] = $tk_desc;
  51. Dever::db('pay/order')->update($update);
  52. }
  53. }
  54. return 'ok';
  55. }
  56. # 这是一个带有安全验证的请求例子
  57. private function test_order($id, $name, $data)
  58. {
  59. $status = Dever::param('status', $data);
  60. if ($status > 0 && $id > 0) {
  61. $send = array();
  62. $info = Dever::db('journal/order')->one($id);
  63. $send['pay_project_id'] = 1;
  64. $send['pay_uid'] = $info['uid'];
  65. $send['pay_order_id'] = $info['order_id'];
  66. $send['pay_tk_pic'] = $info['tk_pic'];
  67. $send['pay_tk_time'] = $info['tk_time'];
  68. $send['pay_tk_desc'] = $info['tk_desc'];
  69. $send['pay_status'] = $status;
  70. $send['dever_token'] = 'test';//自定义key,为空则使用系统的token
  71. # 发送请求
  72. Dever::load('pay/lib/set.updateStatus', $send);
  73. }
  74. }
  75. }