php 抖音支付

直接上代码

createOrder($outOrderNo, $totalAmount, $subject, $body, $validTimestamp, $notifyUrl);
        dd($response);
    }

    /**
     * @param Request $request
     * @return \think\response\Json
     */
    public function notify(Request $request): \think\response\Json
    {
        $notify = $request->param();
        if ($notify['msg_signature'] !== $this->signature($notify, $this->token)) {
            Log::record('回调验证错误');
        } else {
            //获取订单信息
            $order = json_decode($notify['msg'], true);
            //处理订单
        }

        $data = ['err_no' => '0', 'err_tips' => 'success'];
        return json($data);
    }

    /**
     * @param $outOrderNo
     * @param $totalAmount
     * @param $subject
     * @param $body
     * @param $validTimestamp
     * @param $notifyUrl
     * @return array|string
     */
    private function CreateOrder($outOrderNo, $totalAmount, $subject, $body, $validTimestamp, $notifyUrl)
    {
        $params = [
            'app_id'       => $this->appId,
            'out_order_no' => $outOrderNo,
            'total_amount' => $totalAmount,
            'subject'      => $subject,
            'body'         => $body,
            'valid_time'   => $validTimestamp,
            'notify_url'   => $notifyUrl,
            //'cp_extra' => $cpExtra,
            //'thirdparty_id' => $thirdPartyId,
            //'disable_msg' => $disableMsg,
            //'msg_page' => $msgPage,
            //'store_uid' => $storeUid
        ];

        $params = array_filter($params);
        $params['sign'] = $this->signature($params, $this->salt);
        //var_dump($params);die;
        return $this->post(
            'https://developer.toutiao.com/api/apps/ecpay/v1/create_order',
            $params
        );
    }

    /**
     * payment api signature
     * @param array $body
     * @param string $secret
     * @return string
     */
    public static function signature(array $body, string $secret): string
    {
        $filtered = [];
        foreach ($body as $key => $value) {
            if (in_array($key, ['sign', 'app_id', 'thirdparty_id'])) {
                continue;
            }

            $filtered[] =
                is_string($value)
                    ? trim($value)
                    : $value;
        }

        $filtered[] = trim($secret);
        sort($filtered, SORT_STRING);
        return md5(trim(implode('&', $filtered)));
    }

    /**
     * post request
     * @param string $uri
     * @param array $params
     * @param array $headers
     * @return string
     */

    private function post(string $uri, array $params = [], array $headers = []): array
    {
        $headers[] = 'Content-type: application/json';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $uri);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $output = curl_exec($ch);
        curl_close($ch);

        return json_decode($output, true);
    }
}

index方法成功返回
下方示例

{
  "order_id": "6819903302604491021",
  "order_token": "CgsIARCABRgBIAQoARJOCkx+WgXqCUIwTel2V3siEGZ0++poigIM+SMMxtMx798Vj0ZYzoTYBqeNslodUC9X5KAOHkR1YbSBz6I6pXATh5faIGy7R72A9vwm0OczGgA="
}

前端调起tt.pay拉起字节收银台,就行

给TA打赏
共{{data.count}}人
人已打赏
LinuxPHP

Linux系统通过命令行运行PHP 指定运行用户

2022-7-22 14:20:18

PHP

抖音小程序担保支付(php + uniapp)

2022-8-30 9:33:24

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索