WxPayResults.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace common\library\Pay\lib;
  3. /**
  4. *
  5. * 接口调用结果类
  6. * @author widyhu
  7. *
  8. */
  9. use yii;
  10. class WxPayResults extends WxPayDataBase
  11. {
  12. /**
  13. *
  14. * 检测签名
  15. */
  16. public function CheckSign()
  17. {
  18. //fix异常
  19. if(!$this->IsSignSet()){
  20. new WxPayException("签名错误!");
  21. }
  22. $sign = $this->MakeSign();
  23. if($this->GetSign() == $sign){
  24. return true;
  25. }
  26. new WxPayException("签名错误!");
  27. }
  28. /**
  29. *
  30. * 使用数组初始化
  31. * @param array $array
  32. */
  33. public function FromArray($array)
  34. {
  35. $this->values = $array;
  36. }
  37. /**
  38. *
  39. * 使用数组初始化对象
  40. * @param array $array
  41. * @param 是否检测签名 $noCheckSign
  42. */
  43. public static function InitFromArray($array, $noCheckSign = false)
  44. {
  45. $obj = new self();
  46. $obj->FromArray($array);
  47. if($noCheckSign == false){
  48. $obj->CheckSign();
  49. }
  50. return $obj;
  51. }
  52. /**
  53. *
  54. * 设置参数
  55. * @param string $key
  56. * @param string $value
  57. */
  58. public function SetData($key, $value)
  59. {
  60. $this->values[$key] = $value;
  61. }
  62. /**
  63. * 将xml转为array
  64. * @param string $xml
  65. * @throws WxPayException
  66. */
  67. public static function Init($xml)
  68. {
  69. $obj = new self();
  70. $obj->FromXml($xml);
  71. //fix bug 2015-06-29
  72. if($obj->values['return_code'] != 'SUCCESS'){
  73. return $obj->GetValues();
  74. }
  75. $obj->key = Yii::$app->params['wechat']['key'];
  76. $obj->CheckSign();
  77. return $obj->GetValues();
  78. }
  79. }