RefillCallBack.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace refill\sctongqian;
  3. require_once(BASE_HELPER_RAPI_PATH . '/sctongqian/config.php');
  4. use refill;
  5. class RefillCallBack implements refill\IRefillCallBack
  6. {
  7. public function verify($params): bool
  8. {
  9. $sign = $this->sign($params);
  10. if ($params['Sign'] == $sign) {
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. private function sign($params)
  17. {
  18. $content = config::APP_KEY . $params['TimesTamp'] . $params['MOrderID'] . $params['OrderID'] . $params['State'] . $params['ChargeAccount'];
  19. $content .= $params['BuyCount'] . config::App_Secret;
  20. return strtoupper(md5($content));
  21. }
  22. public function notify($params)
  23. {
  24. $status = intval($params['State']);
  25. $order_sn = $params['MOrderID'];
  26. $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
  27. if (empty($order_info)) {
  28. return [false, false, false,false];
  29. }
  30. $order_id = $order_info['order_id'];
  31. if ($status === 2) {
  32. //卡密信息,需返回
  33. $CardInfo = $this->rsa_decode($params['CardInfo']);
  34. return [$order_id, true, false,true];
  35. }
  36. elseif ($status === 3) {
  37. return [$order_id, false, true,true];
  38. }
  39. else {
  40. return [$order_id, false, false,false];
  41. }
  42. }
  43. private function rsa_decode($encrypted)
  44. {
  45. $private_key = config::PRIVATE_KEY;
  46. //使用私钥解密数据
  47. openssl_private_decrypt(base64_decode($encrypted), $decrypted,$private_key);
  48. return $decrypted;
  49. }
  50. }