大佬教程收集整理的这篇文章主要介绍了php 抖音支付,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
直接上代码
在这里<?PHP
declare (Strict_types=1);
namespace app\controller;
use think\facade\Log;
use think\request;
class DemoController
{
protected $appId = "ttc596*********e46e9";
protected $secret = "420c20867e7**********8b005b5ddaa64a5b";
protected $salt = "aLaBzmbdL*******************j574oaeOCX";
protected $token = "123123";
/**
* 显示资源列表
* doc https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/apI/Open-interface/payment/secure/YE
* @return \think\Response
*/
public function index(): \think\Response
{
$outOrderNo = "test21052511401";//开发者侧的订单号
$@R_277_10586@lamount = 1;//支付价格; 接口中参数支付金额单位为[分]
$subject = "测试商品描述";
$body = "测试商品详情";
$validtimestamp = 60 * 60;//订单过期时间(秒);
$notifyUrl = "http://edf17151ed2b.ngrok.io/index.PHP/notify";
$response = $this->createOrder($outOrderNo, $@R_277_10586@lamount, $subject, $body, $validtimestamp, $notifyUrl);
dd($responsE);
}
/**
* @param request $request
* @return \think\response\Json
*/
public function notify(request $request): \think\response\Json
{
$notify = $request->@R_134_1403@;
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 $@R_277_10586@lamount
* @param $subject
* @param $body
* @param $validtimestamp
* @param $notifyUrl
* @return array|String
*/
private function CreateOrder($outOrderNo, $@R_277_10586@lamount, $subject, $body, $validtimestamp, $notifyUrl)
{
$params = [
'app_id' => $this->appId,
'out_order_no' => $outOrderNo,
'@R_277_10586@l_amount' => $@R_277_10586@lamount,
'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);
}
}
插入代码片
{
"order_id": "6819903302604491021",
"order_token": "CgsIARCABRgBIAQoARJOCkx+WgXqCUIwTel2V3siEGZ0++poigIM+SMMxtMx798Vj0ZYzoTYBqeNslodUC9X5KAOHkR1YbSBz6I6pXATh5faIGy7R72A9vwm0OczGgA="
}
前端调起tt.pay拉起字节收银台,就行
以上是大佬教程为你收集整理的php 抖音支付全部内容,希望文章能够帮你解决php 抖音支付所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。