PHP code example of suifeng / applet-paylogin
1. Go to this page and download the library: Download suifeng/applet-paylogin 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/ */
suifeng / applet-paylogin example snippets
$data= \Applet\Pay\Factory::getInstance('Toutiao')->init($config)->getToken();
$code="";//小程序传递过来的
$data= \Applet\Pay\Factory::getInstance('Toutiao')->init($config)->getOpenid($code);
$options=[
'out_order_no'=>1,
'total_amount'=>'2'...
];
appid,valid_time 不需要传递 其他必填都必须传递
$pay= \Applet\Pay\Factory::getInstance('Toutiao')->init($config)->createOrder($options);
$data= \Applet\Pay\Factory::getInstance('Toutiao')->init($config)->decryptPhone($session_key, $iv, $encryptedData);
$Toutiao = \Applet\Pay\Factory::getInstance('Toutiao')->init($config)->findOrder("订单号");
$order = [
'out_order_no' => '',
'out_refund_no' => time(),
'reason' => '说明 都看文档吧',
'refund_amount' => 1, //退款金额
];
$data= \Applet\Pay\Factory::getInstance('Toutiao')->init($config)->applyOrderRefund($order);
$result=\Applet\Pay\Factory::getInstance('Toutiao')->init($Config)->verify();
$msg=$result['msg'];
if($msg['status']=='SUCCESS'){
$msg['cp_orderno'];; //网站订单号
$msg['channel_no']; //流水号
$data=[
"err_no" =>0,
"err_tips"=>"success",
];
return json_encode($data); //必须输出一个 json
}
$token=''; //接口调用凭证access_token
$tpl_id=''; //所需下发的订阅模板id
$open_id=''; //接收者(用户)的 openid
$page='/page/index/index'; //点击模板卡片后的跳转页面
//模板内容 数组
$send_data=[
'thing4' =>'参数1',
'phrase5'=>'参数2'
];
$result=Applet::getInstance('Toutiao')->init($Config)->sendMessage($token,$tpl_id,$open_id,$send_data,$page);
$data= \Applet\Pay\Factory::getInstance('Weixin')->init($config)->getToken();
$code="";
$data= \Applet\Pay\Factory::getInstance('Weixin')->init($config)->getOpenid($code);
$options=[];
$pay= \Applet\Pay\Factory::getInstance('Weixin')->init($config)->set($options);
$data= \Applet\Pay\Factory::getInstance('Weixin')->init($config)->decryptPhone($session_key, $iv, $encryptedData);
$payName='Weixin';//设置驱动
$Baidu = \Applet\Pay\Factory::getInstance('Weixin')->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('Weixin')->init($config)->applyOrderRefund($order);
$result=\Applet\Pay\Factory::getInstance('Weixin')->init($Config)->verify();
if($result['result_code']=='SUCCESS'&&$result['return_code']=='SUCCESS'){
$result['out_trade_no']; //网站订单号
$result['transaction_id']; //流水号
$result['openid']; //支付账户
return 'success'; //必须输出一个 success
}
$token=''; //接口调用凭证access_token
$template_id=''; //所需下发的订阅模板id
$touser=''; //接收者(用户)的 openid
$url='/page/index/index'; //点击模板卡片后的跳转页面
//模板内容 数组
$send_data=[
'thing4' =>'参数1',
'phrase5'=>'参数2'
];
$result=Applet::getInstance('Weixin')->init($Config)->sendMessage($token,$template_id,$touser,$url,$send_data);
$code="";
$data= \Applet\Pay\Factory::getInstance('Alipay')->init($config)->getOpenid($code);
$code='';
$data= \Applet\Pay\Factory::getInstance('Alipay')->init($config)->decryptPhone($code);
$options=[
'out_trade_no'=>1,// 订单号
'total_amount'=>2,// 订单金额,**单位:元**
'buyer_id' =>3,//支付人的 buyer_id
'subject' =>4,// 订单描述
];
$data= \Applet\Pay\Factory::getInstance('Alipay')->init($config)->createOrder($options);
$options=[];//这里是数组
$data = \Applet\Pay\Factory::getInstance('Alipay')->findOrder($options);
$options=[];//这里是数组
$data= \Applet\Pay\Factory::getInstance('Alipay')->init($config)->applyOrderRefund($options);
$result=\Applet\Pay\Factory::getInstance('Alipay')->init($Config)->verify($_POST);
if($result['trade_status']=='TRADE_SUCCESS'||$result['trade_status']=='TRADE_FINISHED'){
return 'success';//必须输出
}
$options=[
'to_user_id' =>'参数1',//接收模板消息的用户 user_id
'user_template_id'=>'参数2',//消息模板ID
'page'=>'',//小程序的跳转页面
//模板参数
'data'=>[
'thing4' =>'参数1',
'phrase5'=>'参数2'
]
];
$result=Applet::getInstance('Alipay')->init($Config)->sendMessage($options);