PHP code example of code-lives / applet-pays
1. Go to this page and download the library: Download code-lives/applet-pays library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
code-lives / applet-pays example snippets
composer
// 第一种使用方法 Factory:: ide 自动提示 Weixin
$pay= \Applet\Pay\Factory::Weixin()->init($config)->set("订单号","金额","描述")->getParam();
// 第二种方法
$PayName='Baidu';//百度
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述")->getParam();
$PayName='Byte';//抖音
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述","描述")->getParam();
$PayName='Weixin';//微信
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述","openid")->getParam();
$PayName='Kuaishou';//快手
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述",'openid', 'access_token')->getParam();
$PayName='Ali';//支付宝小程序
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述",'openid')->getParam();
$PayName='Weixin';//微信公众号【appid 和secret 换成公众号的】
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述","openid")->getParam();
$PayName='Weixin';//微信H5【appid 和secret 换成公众号的】
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述")->getH5Param();
$PayName='Weixin';//微信APP (没有openid)
$pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述")->getParam();
$PayName='Baidu';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
$PayName='Baidu';//设置驱动
$code="";
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
$PayName='Baidu';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $ciphertext);
echo $phone['mobile'];
$PayName='Baidu';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance('Baidu')->init($config);
$order = [
'tpOrderId' => '',//订单号
'access_token' => $Baidu->getToken()['access_token'],
];
$data = $Baidu->findOrder($order);
$order = [
'token' => 'abcd',
'bizRefundBatchId' => 123456,//百度平台订单号
'isSkipAudit' => 1,
'orderId' => 123456,
'refundReason' => '测试退款',
'refundType' => 2,//
'tpOrderId' => '123',//自己平台订单号
'userId' => 123,
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order);
$data = [
"touser_openId" => "",
"template_id" => "",
"page" => "pages/index/index",
"subscribe_id" => '百度from组件subscribe-id 一致',
"data" => json_encode([
'keyword1' => ['value' => "第一个参数"],
'keyword2' => ['value' => "第二个参数"],
'keyword3' => ['value' => "第三个参数"],
])
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token);
$data=[
"errno" => 0,
"msg" => "success",
"data" => array=> [
"msg_key" => 1663314134696897
]
]
$PayName='Byte';//驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
$PayName='Byte';//设置驱动
$code="";
$anonymous_code="";//可以不传
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code,$anonymous_code);
$PayName='Baidu';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
echo $phone['phoneNumber'];
$PayName='Byte';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
$data = $Baidu->findOrder("订单号");
$PayName='Byte';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
$data = $Baidu->settle($order);
$order = [
'out_order_no' => '',
'out_refund_no' => time() . 'refund',
'reason' => '就想退款,咋滴',
'refund_amount' => 1, //退款金额
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order);
//返回 [err_no] => 1
// [err_tips] => 成功
// [refund_no] => 1212
$data = [
'tpl_id' => "模版id",
"open_id" => $parm['openid'],
'data' => [
'律师' => "张三",
"回复时间" => date('Y-m-d H:i:s', time()),
"回复内容" => "我回复你啦",
],
"page" => "pages/index/index",
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token);
$PayName='Weixin';//驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
$PayName='Weixin';//设置驱动
$code="";
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
$PayName='Weixin';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
echo $phone['phoneNumber'];
$PayName='Weixin';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
$data = $Baidu->findOrder("订单号");
$order = [
'out_trade_no' => '123',
'total_fee' => 0.01,
'out_refund_no' => time(),
'refund_fee' => 0.01,
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order);
$data = [
"touser" => "",
"template_id" => "",
"page" => "pages/index/index",
"miniprogram_state" => "developer",
"lang" => "zh_CN",
"data" => [
'thing6' => ['value' => "第一个参数{{thing6.DATA}}"],
'thing7' => ['value' => "第二个参数{{thing7.DATA}}"],
'time8' => ['value' => "第三个参数{{time8.DATA}}"],
],
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token);
$data=[
"errcode" => 0
"errmsg" => "ok"
"msgid" => 123456
]
$PayName='Ali';//设置驱动
$code="";
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
//返回参数
$data = array(
[alipay_system_oauth_token_response] => Array
(
[access_token] => 123
[alipay_user_id] => 123
[auth_start] => 2023-03-26 20:56:36
[expires_in] => 1296000
[re_expires_in] => 2592000
[refresh_token] => auth
[user_id] => 123
)
[sign] =>
)
$PayName='Ali';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
echo $phone['mobile'];
$PayName='Ali';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
$data = $Baidu->findOrder(['out_trade_no' => '1679838318']);
$orders = [
'out_order_no' => $order['out_order_no'],
'refund_amount' => $order['refund_amount'],
];
$PayName='Ali';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order);
$data = [
'to_user_id' => '用户uid',
'user_template_id' => '模版id',
'page' => 'pages/index/index',
'data' => json_encode([
'keyword1' => ['value' => '1'],
'keyword2' => ['value' => '2'],
'keyword3' => ['value' => '3'],
]),
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token);
$PayName='Kuaishou';//设置驱动
$code="";
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
$PayName='Kuaishou';//设置驱动
$code="";
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
$PayName='Kuaishou';//设置驱动
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
echo $phone['phoneNumber'];
$PayName='Kuaishou';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
$data = $Baidu->findOrder("订单号",$access_token);
$orders = [
'out_order_no' => $order['out_order_no'],
'out_refund_no' => $order['out_refund_no'],
'reason' => $order['reason'],
'attach' => $order['attach'],
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order);
//注意 需要设置回调 notify_url 在config 设置 settle_url 如果没有 默认为 notify_url
$orders = [
'out_order_no' => $order['out_order_no'],
'out_settle_no' => $order['out_settle_no'],
'reason' => $order['reason'],
'attach' => $order['attach'],
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->settle($order,$access_token);
$order = [
'out_biz_order_no' => '',
'out_order_no' => '',
'open_id' => '',
'order_create_time' => time(),
'order_status' => 6,
'order_path' => '',
'product_cover_img_id' =>'',
];
$data = \Applet\Pay\Factory::getInstance($PayName)->init($config)->synchronousOrder($order, $token);
$data = \Applet\Pay\Factory::getInstance($PayName)->init($config)->imgUpload('图片路径', $token);
$data = [
"open_id" => "",
"tpl_id" => "",
"page" => "pages/index/index",
"data" => [
'key1' => "第一个",
'key2' => "第二个",
'key3' => "第三个",
]
];
$data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token);
$data=[
"err_no" => 1001,
"err_tips" => "该用户未订阅"
]
$pay = \Applet\Pay\Factory::getInstance('Byte')->init($config);
$status = $pay->notifyCheck(); //验证
if ($status) {
$orderSn = $pay->getNotifyOrder(); //订单数据$orderSn['msg']['cp_orderno'] $orderSn['msg']['seller_uid']
switch ($orderSn['type']) {
case 'payment': // 支付相关回调
/**
*业务处理
*/
echo json_encode(['err_no' => 0, 'err_tips' => 'success']);exit; // 操作成功需要给头条返回的信息
break;
case 'refund': // 退款相关回调
/**
*业务处理
*/
echo json_encode(['err_no' => 0, 'err_tips' => 'success']);exit; // 操作成功需要给头条返回的信息
break;
case 'settle': // 分账相关回调
/**
*业务处理
*/
echo json_encode(['err_no' => 0, 'err_tips' => 'success']);exit; // 操作成功需要给头条返回的信息
break;
default: // 未知数据
return '数据异常';
}
}
$pay = \Applet\Pay\Factory::getInstance('Weixin')->init($config);
$status = $pay->notifyCheck();//验证
if($status){
$order = $pay->getNotifyOrder();//订单数据
//$order['out_trade_no']//平台订单号
//$order['transaction_id']//微信订单号
echo 'success';exit;
}
$pay = \Applet\Pay\Factory::getInstance('Baidu')->init($config);
$status = $pay->notifyCheck();//验证
if($status){
$order = $pay->getNotifyOrder();
//$order['tpOrderId']
//$order['orderId']
//$order['userId']
echo 'success';exit;
}
$pay = \Applet\Pay\Factory::getInstance('Kuaishou')->init($config);
$status = $pay->notifyCheck(); //验证
if ($status) {
$order = $pay->getNotifyOrder(); //订单数据
//$order['data']['out_order_no']//平台订单号
echo json_encode(['result' => 1, 'message_id' => $order['message_id']]);exit;
}
$pay = \Applet\Pay\Factory::getInstance('Ali')->init($config);
$status = $pay->notifyCheck(); //验证
if ($status) {
$order = $pay->getNotifyOrder(); //订单数据
//$order['out_trade_no']//平台订单号
}