ByteDancePay.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\service\byte_dance;
  3. use think\Cache;
  4. use think\Collection;
  5. class ByteDancePay implements ByteDanceInterface {
  6. protected $data=[
  7. 'out_order_no'=>'',
  8. 'total_amount'=>'',
  9. 'subject'=>'',
  10. 'body'=>'',
  11. 'valid_time'=>86400,
  12. 'notify_url'=>'',
  13. 'thirdparty_id'=>''
  14. ];
  15. public function __construct()
  16. {
  17. }
  18. /**
  19. * @param mixed $order_no
  20. * @param $amount
  21. * @param $subject
  22. * @return ByteDancePay
  23. */
  24. public static function setInfo($order_no,$amount,$subject)
  25. {
  26. $class=new self;
  27. $class->data['app_id']=ByteDance::appId();
  28. $class->data['out_order_no'] = $order_no;
  29. $class->data['total_amount'] = $amount*100;
  30. $class->data['subject'] = $subject;
  31. $class->data['body'] = $subject;
  32. $class->data['notify_url']=request()->domain().'/index/payment/notify_dy/order_no/'.$order_no;
  33. return $class;
  34. }
  35. /**
  36. * @param mixed $order_no
  37. * @param $amount
  38. * @param $subject
  39. * @return ByteDancePay
  40. */
  41. public static function setInfo2($order_no,$amount,$subject)
  42. {
  43. $class=new self;
  44. $class->data['app_id']=ByteDance::appIdTwo();
  45. $class->data['out_order_no'] = $order_no;
  46. $class->data['total_amount'] = $amount*100;
  47. $class->data['subject'] = $subject;
  48. $class->data['body'] = $subject;
  49. $class->data['notify_url']=request()->domain().'/index/payment/notify_dy/order_no/'.$order_no;
  50. return $class;
  51. }
  52. public function get()
  53. {
  54. $data=$this->data;
  55. $data['sign']=ByteDance::sign($data);
  56. $order=ByteDance::httpPost('https://developer.toutiao.com/api/apps/ecpay/v1/create_order',$data);
  57. $obj=ByteDanceResult::make();
  58. foreach ($order as $key=>$item){
  59. $obj->offsetSet($key,$item);
  60. }
  61. return $obj;
  62. }
  63. }
  64. /**
  65. * @property string $order_id
  66. * @property string $order_token
  67. * @property string $url
  68. */
  69. class ByteDanceResult extends Collection {}