Youluo.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Libs\Pay\Merchants;
  3. use GuzzleHttp\Client;
  4. use Log;
  5. /**
  6. *
  7. *
  8. * commit e0bb38efab0b546f00ffd8f5f485032b7cda4ad9
  9. Author: zz <524914631@qq.com>
  10. Date: Thu Aug 3 18:00:57 2017 +0800
  11. dist
  12. commit 90a52f5073dac91e58487d9966faf55b55cf849f
  13. Author: zz <524914631@qq.com>
  14. Date: Thu Aug 3 17:33:32 2017 +0800
  15. dist
  16. commit 6e84098457780a2d0e57510eca4cfaf8a5b65ba5
  17. Author: zz <524914631@qq.com>
  18. Date: Wed Aug 2 13:39:44 2017 +0800
  19. apple online check
  20. */
  21. class Youluo {
  22. private $merchant_key;
  23. private $merchant_id;
  24. private $appId;
  25. function __construct()
  26. {
  27. $this->merchant_key = 'bc9f9ad017460b5ccb6d237dca39d5b9';//'d014da1ab33d8f3ddfaf7e5a81724f1a';
  28. $this->merchant_id = '26102295';//'26104515';
  29. $this->appId = 'wxcccc8abc4b42abab';//'26104515';
  30. }
  31. //生成订单
  32. function send($trade_no,$fee=1,$ip="192.168.1.21",$return_url)
  33. {
  34. $client = new client(['base_uri'=>'http://api.ulopay.com/','timeout'=>20]);
  35. $data = [
  36. 'trade_type'=>'trade.weixin.jspay',
  37. 'mch_id'=>$this->merchant_id,
  38. 'out_trade_no'=>$trade_no,
  39. 'body'=>'充值',
  40. 'total_fee'=>$fee*100,
  41. 'spbill_create_ip'=>$ip,
  42. 'notify_url'=>env('PAY_NOFITY_URL'),
  43. 'nonce_str'=>md5(time()),
  44. 'return_url'=>$return_url
  45. ];
  46. $data['sign'] = $this->sign($data);
  47. $response = $client->request('POST',"pay/unifiedorder",['body'=>arrayToXml($data)])->getBody()->getContents();
  48. return $this->getPayInfo($response);
  49. }
  50. function sign($params)
  51. {
  52. $signPars = "";
  53. ksort($params);
  54. foreach($params as $k => $v) {
  55. if("" != $v && "sign" != $k) {
  56. $signPars .= $k . "=" . $v . "&";
  57. }
  58. }
  59. $signPars .= "key=".$this->merchant_key;
  60. $sign = strtoupper(md5($signPars));
  61. return $sign;
  62. }
  63. function getPayInfo($response)
  64. {
  65. $return_info = (array)simplexml_load_string($response, null, LIBXML_NOCDATA);
  66. $nonceStr = md5(time());
  67. $timeStamp = time();
  68. $pay_info = [
  69. 'appId' => $this->appId,
  70. 'package' => 'prepay_id='.$return_info['prepay_id'],
  71. 'nonceStr' => $nonceStr,
  72. 'timeStamp' => $timeStamp,
  73. 'signType' => 'MD5'
  74. ];
  75. $pay_info['paySign'] = $this->sign($pay_info);
  76. $pay_info['prepay_url'] = $return_info['prepay_url'];
  77. return $pay_info;
  78. }
  79. }