InterfaceDemo.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. include_once 'lib/HttpHelper.php';
  3. include_once 'lib/SignatureHelper.php';
  4. include_once 'lib/Configuration.php';
  5. /**
  6. * 验证登陆信息接口
  7. * @param type $userId
  8. * @param type $session
  9. */
  10. function verifySession($userId,$session) {
  11. $params = array('appId' => Configuration::APP_ID,'uid' => $userId, 'session' => $session);
  12. $signObj = new SignatureHelper();
  13. $signature = $signObj->sign($params, Configuration::SECRET_KEY);
  14. $params['signature'] = $signature;
  15. $request = new HttpHelper();
  16. $response = $request->get(Configuration::VERIFY_SESSION_URL, $params);
  17. //TODO: 后续业务逻辑处理
  18. echo $response;
  19. }
  20. /**
  21. * 查询订单接口
  22. * @param type $userId
  23. * @param type $cpOrderId
  24. */
  25. function queryOrder($userId,$cpOrderId) {
  26. $params = array('appId' => Configuration::APP_ID,'uid' => $userId, 'cpOrderId' => $cpOrderId);
  27. $signObj = new SignatureHelper();
  28. $signature = $signObj->sign($params, Configuration::SECRET_KEY);
  29. $params['signature'] = $signature;
  30. $request = new HttpHelper();
  31. $response = $request->get(Configuration::QUERY_ORDER_URL, $params);
  32. //TODO: 后续业务逻辑处理
  33. echo $response;
  34. }
  35. /**
  36. * 接收订单通知接口
  37. */
  38. function notify(){
  39. $reqparams = $_REQUEST;
  40. $params = array();
  41. $httpHelper = new HttpHelper();
  42. foreach ($reqparams as $key => $value) {
  43. if($key != 'signature'){
  44. $params[$key] = $httpHelper->urlDecode($value);
  45. }
  46. }
  47. $signature = $reqparams['signature'];
  48. $signObj = new SignatureHelper();
  49. if($signObj->verifySignature($params, $signature, Configuration::SECRET_KEY)){
  50. //TODO:后续业务逻辑处理
  51. echo '{"errcode":200}';
  52. }else{
  53. echo '{"errcode":1525}';
  54. }
  55. }