Pay.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace Journal\Lib;
  3. use Dever;
  4. class Pay
  5. {
  6. private $key = 'jmss_2018';
  7. public function test_api()
  8. {
  9. $data['status'] = 1;
  10. $this->order(1, 'test', $data);
  11. }
  12. public function order($id, $name, $data)
  13. {
  14. $status = Dever::param('status', $data);
  15. if ($status > 0 && $id > 0) {
  16. $send = array();
  17. $info = Dever::db('journal/order')->one($id);
  18. $send['pay_project_id'] = 1;
  19. $send['pay_uid'] = $info['uid'];
  20. $send['pay_order_id'] = $info['order_id'];
  21. $send['pay_tk_pic'] = Dever::param('tk_pic', $data);
  22. $send['pay_tk_time'] = Dever::param('tk_time', $data);
  23. $send['pay_tk_desc'] = Dever::param('tk_desc', $data);
  24. $send['pay_status'] = $status;
  25. $send['dever_token'] = $this->key;
  26. Dever::load('pay/lib/set.updateStatus', $send);
  27. }
  28. }
  29. /**
  30. * 支付成功后,调取的接口 这里的安全以后再升级吧,升级成和pay/lib/set.updateStatus一样的
  31. *
  32. * @return mixed
  33. */
  34. public function act_api($param = array())
  35. {
  36. $send = Dever::preInput('pay_');
  37. $key = md5($this->key);
  38. ksort($send);
  39. $send['signature'] = md5($key . '&' . http_build_query($send));
  40. $signature = Dever::input('signature');
  41. if ($send['signature'] == $signature) {
  42. $product_id = $send['pay_product_id'];
  43. $uid = $send['pay_uid'];
  44. $cash = $send['pay_cash'];
  45. $order_id = $send['pay_order_id'];
  46. $status = $send['pay_status'];
  47. $msg = $send['pay_msg'];
  48. $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  49. if ($send['pay_status'] == 2 && $order) {
  50. $update = array();
  51. $update['where_id'] = $order['id'];
  52. $update['status'] = 2;
  53. if ($order['type'] == 3) {
  54. # 购买兑换码
  55. $product_num = 1;
  56. $code_num = 1;
  57. if ($order['buy_id'] > 0) {
  58. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  59. $product_num = $buy['num'];
  60. $code_num = $buy['code'];
  61. }
  62. if ($code_num > 1) {
  63. $product_num = intval($product_num/$code_num);
  64. for ($i = 0; $i < $code_num; $i++) {
  65. $update['code'] = Dever::load('code/lib/core')->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $uid, $order['order_id']);
  66. }
  67. } else {
  68. $update['code'] = Dever::load('code/lib/core')->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $uid, $order['order_id']);
  69. }
  70. }
  71. Dever::db('journal/order')->update($update);
  72. if ($order['type'] != 1) {
  73. return;
  74. }
  75. # 订阅
  76. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  77. $score = false;
  78. $num = false;
  79. if ($order['buy_id'] > 0) {
  80. $info = Dever::db('journal/info')->one($order['product_id']);
  81. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  82. if ($info && $buy && $info['score'] > 0) {
  83. $score = $buy['num'] * $info['score'];
  84. } elseif ($info && $buy) {
  85. $num = $buy['num'];
  86. }
  87. }
  88. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  89. # 发消息
  90. $journal = Dever::db('journal/info')->one($order['product_id']);
  91. if (Dever::project('message')) {
  92. Dever::load('message/lib/data')->push(-1, $uid, '购买提醒', '购买成功,您获得了 '.$journal['name'].' 的阅读资格!', 11, $order['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  93. }
  94. $user = Dever::db('passport/user')->one($uid);
  95. # 发短信
  96. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  97. $send = array();
  98. $send['name'] = $journal['name'];
  99. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  100. }
  101. # 发模板消息
  102. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  103. if ($wechat && Dever::project('wechat_applet')) {
  104. $send['key'] = 'buy_journal';
  105. $send['project_id'] = $order['cate_id'];
  106. $send['touser'] = $wechat['openid'];
  107. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  108. $send['data'] = array
  109. (
  110. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  111. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  112. );
  113. $send['data'] = json_encode($send['data']);
  114. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  115. if ($send['form_id']) {
  116. Dever::load('wechat_applet/msg.send', $send);
  117. }
  118. }
  119. } else {
  120. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  121. }
  122. }
  123. }
  124. public function send_api()
  125. {
  126. $uid = Dever::input('uid', 8);
  127. # 发模板消息
  128. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  129. if ($wechat && Dever::project('wechat_applet')) {
  130. $send['key'] = 'buy_journal';
  131. $send['project_id'] = 2;
  132. $send['touser'] = $wechat['openid'];
  133. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  134. $send['data'] = array
  135. (
  136. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  137. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  138. );
  139. $send['data'] = json_encode($send['data']);
  140. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  141. if ($send['form_id']) {
  142. Dever::load('wechat_applet/msg.send', $send);
  143. }
  144. }
  145. }
  146. }