Coder Social home page Coder Social logo

pays's Introduction

微信小程序、字节小程序、百度小程序、快手小程序、微信 App、微信 H5(支付、手机号解密、获取 Token、支付异步通知、退款、订单查询)

目录、微信小程序、字节小程序、百度小程序、微信 App 支付

安装说明

composer require code-lives/applet-pays 5.0

功能支持

第三方 token openid 支付 回调 退款 订单查询 解密手机号 分账
微信小程序 x
微信h5 x x x x
微信公众号 x x x x
百度小程序 x
字节小程序
快手小程序
微信APP x x x

预下单

    // 金额单位分 100=1元 
    $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='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='Kuaishou';//快手
    $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述",'openid', 'access_token')->getParam();

百度小程序

Config

参数名字 类型 必须 说明
appkey string 百度小程序 appkey
payappKey string 百度小程序支付 appkey
appSecret string 百度小程序 aapSecret
dealId int 百度小程序支付凭证
isSkipAudit int 默认为 0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。
rsaPriKeyStr string 私钥(只需要一行长串,不需要文件)
rsaPubKeyStr string 百度小程序支付的平台公钥(支付回调需要)

token

    $payName='Baidu';//设置驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
    //成功 array
    //失败 false
返回参数 类型 必须 说明
expires_in string 凭证有效时间,单位:秒
session_key string session_key
access_token string 获取到的凭证

openid

    $payName='Baidu';//设置驱动
    $code="";
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
    //成功 array
    //失败 false
返回参数 类型 必须 说明
session_key string session_key
openid string 用户 openid

解密手机号

    $payName='Baidu';//设置驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $ciphertext);
    echo $phone['mobile'];
    // 成功 array
    // 失败 false

百度订单查询

参数名字 类型 必须 说明
access_token string 根据上面的获取 token
tpOrderId string 平台订单号
    $payName='Baidu';//设置驱动
    $Baidu = \Applet\Pay\Factory::getInstance('Baidu')->init($config);
    $order = [
            'tpOrderId' => '',//订单号
            'access_token' => $Baidu->getToken()['access_token'],
        ];
    $data = $Baidu->findOrder($order);
    // 成功 array 【自己看手册】
    // 失败 false

百度退款

参数名字 类型 必须 说明
access_token string 根据上面的获取 token
bizRefundBatchId int 百度平台的订单号
isSkipAudit int 默认为 0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。
orderId int 百度平台的订单号
refundReason string 退款描述
refundType int 退款类型 1:用户发起退款;2:开发者业务方客服退款;3:开发者服务异常退款。百度小程序支付的平台公钥
tpOrderId string 自己平台订单号
userId int 用户 uid(不是自己平台 uid)
    $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);
    //返回 true false

字节小程序

Config

参数名字 类型 必须 说明
token string 担保交易回调的 Token(令牌)
salt string 担保交易的 SALT
merchant_id string 担保交易的商户号
app_id int 小程序的 APP_ID
secret string 小程序的 APP_SECRET
notify_url string 支付回调 url
settle_url string 分账回调 url,没有默认支付回调 url

token

    $payName='Byte';//驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
    //成功 array
    //失败 false
返回参数 类型 必须 说明
expires_in string 凭证有效时间,单位:秒
access_token string 获取到的凭证

openid

    $payName='Byte';//设置驱动
    $code="";
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
    //成功 array
    //失败 false
返回参数 类型 必须 说明
session_key string session_key
openid string 用户 openid
unionid string unionid

解密手机号

    $payName='Baidu';//设置驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
    echo $phone['phoneNumber'];
    // 成功 array
    // 失败 false

字节订单查询

    $payName='Byte';//设置驱动
    $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
    $data = $Baidu->findOrder("订单号");
    // 成功 array 【自己看手册】
    // 失败 false

字节分账

参数名字 类型 必须 说明
out_order_no string 平台订单号
out_settle_no string 自定义订单号
settle_desc int 分账描述
cp_extra string 开发者自定义字段,回调原样回传
    $payName='Byte';//设置驱动
    $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
    $data = $Baidu->settle($order);
    // 成功 array 【自己看手册】
    // 失败 false

字节退款

参数名字 类型 必须 说明
out_order_no string 平台订单号
out_refund_no int 自定义订单号
reason int 退款说明
refund_amount string 退款金额
    $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

微信小程序

Config

参数名字 类型 必须 说明
appid int 小程序 appid
secret int 小程序 secret
mch_id string 商户 mch_id
mch_key string 商户 mch_key
notify_url string 异步地址
cert_pem string cert_pem 证书
key_pem string key_pem 证书
trade_type string 默认为:JSAPI。MWEB:代表微信 H5 、JSAPI:公众号或小程序

token

    $payName='Weixin';//驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken();
    //成功 array
    //失败 false
返回参数 类型 必须 说明
expires_in string 凭证有效时间,单位:秒
access_token string 获取到的凭证

openid

    $payName='Weixin';//设置驱动
    $code="";
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
    //成功 array
    //失败 false
返回参数 类型 必须 说明
session_key string session_key
openid string 用户 openid
unionid string unionid

微信解密手机号

    $payName='Weixin';//设置驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
    echo $phone['phoneNumber'];
    // 成功 array
    // 失败 false

微信订单查询

    $payName='Weixin';//设置驱动
    $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
    $data = $Baidu->findOrder("订单号");
    // 成功 array 【自己看手册】
    // 失败 false

微信退款

参数名字 类型 必须 说明
out_trade_no string 平台订单号
out_refund_no strging 自定义订单号
refund_fee int 退款金额
total_fee int 订单金额
refund_desc string 退款原因
    $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);
    //返回 成功 返回订单号  否则 false

快手小程序

Config

参数名字 类型 必须 说明
app_id int 小程序 appid
app_secret int 小程序 secret
notify_url string 回调地址
settle_url string 结算回调地址,没有就默认notify_url
type int 类目

openid

    $payName='Kuaishou';//设置驱动
    $code="";
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code);
返回参数 类型 必须 说明
session_key string session_key
open_id string 用户 open_id
result string 状态 1 是成功

快手解密手机号

    $payName='Kuaishou';//设置驱动
    $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData);
    echo $phone['phoneNumber'];
    // 成功 array
    // 失败 false

快手订单查询

    $payName='Kuaishou';//设置驱动
    $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config);
    $data = $Baidu->findOrder("订单号",$access_token);
    // 成功 array 【自己看手册】

快手退款

参数名字 类型 必须 说明
out_trade_no string 平台订单号
out_refund_no strging 自定义订单号
refund_amount int 退款金额
reason string 退款原因
access_token string access_token
attach string 自定义
    $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);
    //返回 成功

快手结算

参数名字 类型 必须 说明
out_order_no string 平台订单号
out_settle_no strging 自定义订单号
reason string 退款原因
access_token string access_token
attach string 自定义
    //注意 需要设置回调 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);
    //返回 成功

微信 APP

Config

参数名字 类型 必须 说明
appid int 开发平台 appid
secret int 开放平台 secret
mch_id string 商户 mch_id
mch_key string 商户 mch_key
trade_type string APP
notify_url string 异步地址

异步通知

字节

    $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 '数据异常';
        }
    }

微信回调(通用微信 H5 支付、小程序、微信公众号) 记得改 config 配置

    $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;
        }

随便 (打赏 or star or fork)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.