Pay.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Journal\Lib;
  3. use Dever;
  4. class Pay
  5. {
  6. /**
  7. * 支付成功后,调取的接口
  8. *
  9. * @return mixed
  10. */
  11. public function act_api($param = array())
  12. {
  13. $send = Dever::preInput('pay_');
  14. $key = md5('jmss_2018');
  15. ksort($send);
  16. $send['signature'] = md5($key . '&' . http_build_query($send));
  17. $signature = Dever::input('signature');
  18. if ($send['signature'] == $signature) {
  19. $product_id = $send['pay_product_id'];
  20. $uid = $send['pay_uid'];
  21. $cash = $send['pay_cash'];
  22. $order_id = $send['pay_order_id'];
  23. $status = $send['pay_status'];
  24. $msg = $send['pay_msg'];
  25. $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  26. if ($send['pay_status'] == 2 && $order) {
  27. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 2));
  28. # 订阅
  29. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  30. $score = false;
  31. $num = false;
  32. if ($order['buy_id'] > 0) {
  33. $info = Dever::db('journal/info')->one($order['product_id']);
  34. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  35. if ($info && $buy && $info['score'] > 0) {
  36. $score = $buy['num'] * $info['score'];
  37. } elseif ($info && $buy) {
  38. $num = $buy['num'];
  39. }
  40. }
  41. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  42. # 发消息
  43. $journal = Dever::db('journal/info')->one($order['product_id']);
  44. Dever::load('message/lib/data')->push(-1, $uid, '购买提醒', '购买成功,您获得了 '.$journal['name'].' 的阅读资格!', $type = 1);
  45. # 发模板消息
  46. /*
  47. $send['key'] = 'pay';
  48. $send['project_id'] = 1;
  49. $send['touser'] = 'pay';
  50. $send['page'] = 'page';
  51. $send['data'] = array
  52. (
  53. 'keyword1' => array('value', 1),
  54. );
  55. $send['form_id'] = 'pay';
  56. Dever::load('wechat_applet/msg.send', $send);
  57. */
  58. # 发短信
  59. } else {
  60. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  61. }
  62. }
  63. }
  64. }