PayThreeBusiness.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\business;
  3. use support\Db;
  4. use support\Redis;
  5. use yzh52521\EasyHttp\Http;
  6. class PayThreeBusiness
  7. {
  8. static private $url="http://mi.feicuipay.com/optimus/collect/placeOrder";
  9. static private $apikey='bbe90c3a0ebb0c0a13f2c526a5c2543b';
  10. static private $memberid='107912662';
  11. /**
  12. * @param array $param[
  13. * order_no
  14. * ]
  15. * @return array
  16. */
  17. static public function payment($order_no,$pay_bankcode,$money,$url = '')
  18. {
  19. if (empty($url)) {
  20. $url = getenv('WEB_HOST');
  21. }
  22. $arr = [
  23. 'method' => 'placeOrder',
  24. 'timestamp' => date('Y-m-d H:i:s'),
  25. 'memberId' => (int)self::$memberid,//商户号
  26. 'channelCode' => $pay_bankcode,//通道类型
  27. 'callerOrderId' => (string)$order_no,//商户订单号
  28. 'amount' => (int)bcmul($money, 100),//金额,单位为分
  29. 'merchantCallbackUrl' => (string)getenv('API_HOST') . '/api/pay/payment_callback_three.html',//异步通知地址,支付成功后将支付成功消息以POST请求发送给这个网址
  30. 'returnUrl' => (string)$url
  31. ];
  32. $arr['sign'] = self::payMd5sign($arr);
  33. $data = Http::asJson()->post(self::$url, $arr)->array();
  34. return ['data' => $data, 'arr' => $arr];
  35. }
  36. static public function payMd5sign(array $param)
  37. {
  38. ksort($param); //ASCII码排序
  39. $md5str = '';
  40. foreach ($param as $key => $val) {
  41. $md5str = $md5str. $key . $val;
  42. }
  43. $md5str = self::$apikey.$md5str.self::$apikey;
  44. //获取sign
  45. $sign = md5($md5str);
  46. //转换成字符串并且拼接上密钥
  47. return $sign;
  48. }
  49. }