PayTwoBusiness.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\business;
  3. use support\Db;
  4. use support\Redis;
  5. use yzh52521\EasyHttp\Http;
  6. class PayTwoBusiness
  7. {
  8. static private $url="http://pay.qtpal.click/api/pay/create_order";
  9. static private $apikey='N4IYERM0FHJPXRJ6U82HHE2BLSQRJFG488KWD2Z1AEWNPDRFVICRW91XHLW41QOZPU0I4ECJLSQQTZ7ORUD80RRLU6V4W2WTOSYY6N7QYIG3A0KOAU7BN2AHH2Y2HK8E';
  10. static private $memberid=10569;
  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. 'mchId' => (int)self::$memberid,//商户号
  24. 'productId' => (int)$pay_bankcode,//通道类型
  25. 'mchOrderNo' => (string)$order_no,//商户订单号
  26. 'amount' => (int)bcmul($money,100),//金额,单位为分
  27. 'notifyUrl' => (string)getenv('API_HOST').'/api/pay/payment_callback_two.html',//异步通知地址,支付成功后将支付成功消息以POST请求发送给这个网址
  28. 'returnUrl' => (string)$url
  29. ];
  30. $arr['sign']=self::payMd5sign($arr);
  31. $data=Http::post(self::$url,$arr)->array();
  32. return ['data'=>$data,'arr'=>$arr];
  33. }
  34. static public function payMd5sign(array $param)
  35. {
  36. ksort($param); //ASCII码排序
  37. $md5str = [];
  38. foreach ($param as $key => $val) {
  39. $md5str[] = $key . "=" . $val ;
  40. }
  41. $sign = strtoupper(md5(implode('&',$md5str) . "&key=" .self::$apikey));
  42. //转换成字符串并且拼接上密钥
  43. return $sign;
  44. }
  45. }