12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\service\byte_dance;
- use think\Cache;
- use think\Collection;
- class ByteDancePay implements ByteDanceInterface {
- protected $data=[
- 'out_order_no'=>'',
- 'total_amount'=>'',
- 'subject'=>'',
- 'body'=>'',
- 'valid_time'=>86400,
- 'notify_url'=>'',
- 'thirdparty_id'=>''
- ];
- public function __construct()
- {
- }
- /**
- * @param mixed $order_no
- * @param $amount
- * @param $subject
- * @return ByteDancePay
- */
- public static function setInfo($order_no,$amount,$subject)
- {
- $class=new self;
- $class->data['app_id']=ByteDance::appId();
- $class->data['out_order_no'] = $order_no;
- $class->data['total_amount'] = $amount*100;
- $class->data['subject'] = $subject;
- $class->data['body'] = $subject;
- $class->data['notify_url']=request()->domain().'/index/payment/notify_dy/order_no/'.$order_no;
- return $class;
- }
- public function get()
- {
- $data=$this->data;
- $data['sign']=$this->sign($data);
- $order=ByteDance::httpPost('https://developer.toutiao.com/api/apps/ecpay/v1/create_order',$data);
- $obj=ByteDanceResult::make();
- foreach ($order as $key=>$item){
- $obj->offsetSet($key,$item);
- }
- return $obj;
- }
- protected function sign($map) {
- $rList = array();
- foreach($map as $k =>$v) {
- if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id")
- continue;
- $value = trim(strval($v));
- $len = strlen($value);
- if ($len > 1 && substr($value, 0,1)=="\"" && substr($value,$len, $len-1)=="\"")
- $value = substr($value,1, $len-1);
- $value = trim($value);
- if ($value == "" || $value == "null")
- continue;
- array_push($rList, $value);
- }
- array_push($rList, config('site.byte_dance_mapp_pay_salt'));
- sort($rList, 2);
- return md5(implode('&', $rList));
- }
- }
- /**
- * @property string $order_id
- * @property string $order_token
- * @property string $url
- */
- class ByteDanceResult extends Collection {}
|