├── .gitattributes ├── composer.json ├── src └── Factory.php ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | /.github export-ignore -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code-lives/applet-pays", 3 | "description": "微信小程序、抖音(头条)小程序、百度小程序、支付宝小程序、快手小程序、微信App、微信公众号、微信H5(支付、手机号解密、获取Token、支付异步通知、退款、订单查询、分账、模版消息)", 4 | "type": "library", 5 | "version": "5.9", 6 | "license": "MIT", 7 | "authors": [{ 8 | "name": "code-lives", 9 | "email": "948870149@qq.com" 10 | }], 11 | "minimum-stability": "stable", 12 | "require": { 13 | "code-lives/weixin": "^1.0.0", 14 | "code-lives/byte": "^1.0.0", 15 | "code-lives/baidu": "^1.0.0", 16 | "code-lives/kuaishou": "^1.0.0", 17 | "code-lives/ali": "^1.0.0" 18 | }, 19 | "autoload": { 20 | "psr-4": { "Applet\\Pay\\": "src" } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Factory.php: -------------------------------------------------------------------------------- 1 | '\Applet\Assemble\Baidu', 17 | 'Byte' => '\Applet\Assemble\Byte', 18 | 'Weixin' => '\Applet\Assemble\Weixin', 19 | 'Kuaishou' => '\Applet\Assemble\Kuaishou', 20 | 'Ali' => '\Applet\Assemble\Ali', 21 | ]; 22 | 23 | public static function getInstance($ClassName) 24 | { 25 | static $class; 26 | if (isset($class[$ClassName])) { 27 | return $class[$ClassName]; 28 | } 29 | 30 | return $class[$ClassName] = new self::$instance[$ClassName](); 31 | } 32 | 33 | public static function __callStatic($method, $args) 34 | { 35 | return self::getInstance($method, $args); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 code-lives 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | GitHub forks 3 | GitHub forks 4 | GitHub forks 5 | GitHub 6 | 7 |

8 | 9 | #### 公告 2023-11-3 10 | 11 | > 我辞职不干互联网了,所以一些配置就没了,但是还会留意 issues(有邮件等通知)。有想维护这个 SDK 的小伙伴可以提交对应仓库的 PR。 12 | 13 | | 第三方 | token | openid | 支付 | 回调 | 退款 | 订单查询 | 手机号 | 分账 | 模版消息 | 仓库 | 14 | | :-------------------------------------------------------------------------------------------------: | :---: | :----: | :--: | :--: | :--: | :------: | :----: | :--: | :------: | ---------------------------------------------- | 15 | | [微信小程序](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | x | ✓ | [地址](https://github.com/code-lives/weixin) | 16 | | [百度小程序](https://smartprogram.baidu.com/docs/develop/function/tune_up_2.0/) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | x | ✓ | [地址](https://github.com/code-lives/baidu) | 17 | | [抖音小程序](https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/introduction/overview/) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | [地址](https://github.com/code-lives/byte) | 18 | | [快手小程序](https://mp.kuaishou.com/docs/develop/server/epay/interfaceDefinition.html) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | x | [地址](https://github.com/code-lives/kuaishou) | 19 | | [支付宝小程序](https://opendocs.alipay.com/mini/03l5wn) | x | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | x | ✓ | [地址](https://github.com/code-lives/ali) | 20 | | 微信 h5 | x | x | ✓ | ✓ | ✓ | ✓ | x | x | x | [地址](https://github.com/code-lives/weixin) | 21 | | 微信 APP | x | ✓ | ✓ | ✓ | ✓ | ✓ | x | x | x | [地址](https://github.com/code-lives/weixin) | 22 | | 微信公众号 | x | x | ✓ | ✓ | ✓ | ✓ | x | x | ✓ | [地址](https://github.com/code-lives/weixin) | 23 | 24 | ## 安装 25 | 26 | ```php 27 | composer require code-lives/applet-pays 5.9 28 | ``` 29 | 30 | ### ⚠️ 注意 31 | 32 | > 金额单位分 100=1 元 33 | 34 | > 微信支付未使用 APIv3 接口规则 35 | 36 | > 获取 openid 接口 统一 openid 字段(因快手返回的 open_id) 37 | 38 | > 返回结果 array 由开发者自行判断 39 | 40 | > 抖音小程序由字节小程序转变而来,支持多端(头条、抖音、今日头条等关联应用) 41 | 42 | # 预下单 43 | 44 | ```php 45 | // 第一种使用方法 Factory:: ide 自动提示 Weixin 46 | $pay= \Applet\Pay\Factory::Weixin()->init($config)->set("订单号","金额","描述")->getParam(); 47 | 48 | // 第二种方法 49 | $PayName='Baidu';//百度 50 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述")->getParam(); 51 | 52 | $PayName='Byte';//抖音 53 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述","描述")->getParam(); 54 | 55 | $PayName='Weixin';//微信 56 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述","openid")->getParam(); 57 | 58 | $PayName='Kuaishou';//快手 59 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述",'openid', 'access_token')->getParam(); 60 | 61 | $PayName='Ali';//支付宝小程序 62 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述",'openid')->getParam(); 63 | 64 | $PayName='Weixin';//微信公众号【appid 和secret 换成公众号的】 65 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述","openid")->getParam(); 66 | 67 | $PayName='Weixin';//微信H5【appid 和secret 换成公众号的】 68 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述")->getH5Param(); 69 | 70 | $PayName='Weixin';//微信APP (没有openid) 71 | $pay= \Applet\Pay\Factory::getInstance($PayName)->init($config)->set("订单号","金额","描述")->getParam(); 72 | 73 | ``` 74 | 75 | # 百度小程序 76 | 77 | ### Config 78 | 79 | | 参数名字 | 类型 | 必须 | 说明 | 80 | | --------------- | ------ | ---- | --------------------------------------------------------------- | 81 | | appkey | string | 是 | 百度小程序 appkey | 82 | | payappKey | string | 是 | 百度小程序支付 appkey | 83 | | appSecret | string | 是 | 百度小程序 aapSecret | 84 | | dealId | int | 是 | 百度小程序支付凭证 | 85 | | isSkipAudit | int | 是 | 默认为 0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。 | 86 | | rsaPriKeyStr | string | 是 | 私钥(只需要一行长串,不需要文件) | 87 | | rsaPubKeyStr | string | 是 | 百度小程序支付的平台公钥(支付回调需要) | 88 | | notifyUrl | string | 否 | 异步回调地址 | 89 | | refundNotifyUrl | string | 否 | 退款异步回调地址 | 90 | 91 | ### Token 92 | 93 | ```php 94 | $PayName='Baidu';//设置驱动 95 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken(); 96 | ``` 97 | 98 | | 返回参数 | 类型 | 必须 | 说明 | 99 | | ------------ | ------ | ---- | ---------------------- | 100 | | expires_in | string | 是 | 凭证有效时间,单位:秒 | 101 | | session_key | string | 是 | session_key | 102 | | access_token | string | 是 | 获取到的凭证 | 103 | 104 | ### Openid 105 | 106 | ```php 107 | $PayName='Baidu';//设置驱动 108 | $code=""; 109 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code); 110 | ``` 111 | 112 | | 返回参数 | 类型 | 必须 | 说明 | 113 | | ----------- | ------ | ---- | ----------- | 114 | | session_key | string | 是 | session_key | 115 | | openid | string | 是 | 用户 openid | 116 | 117 | ### 解密手机号 118 | 119 | ```php 120 | $PayName='Baidu';//设置驱动 121 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $ciphertext); 122 | echo $phone['mobile']; 123 | ``` 124 | 125 | ### 百度订单查询 126 | 127 | | 参数名字 | 类型 | 必须 | 说明 | 128 | | ------------ | ------ | ---- | -------------------- | 129 | | access_token | string | 是 | 根据上面的获取 token | 130 | | tpOrderId | string | 是 | 平台订单号 | 131 | 132 | ```php 133 | $PayName='Baidu';//设置驱动 134 | $Baidu = \Applet\Pay\Factory::getInstance('Baidu')->init($config); 135 | $order = [ 136 | 'tpOrderId' => '',//订单号 137 | 'access_token' => $Baidu->getToken()['access_token'], 138 | ]; 139 | $data = $Baidu->findOrder($order); 140 | ``` 141 | 142 | ### 百度退款 143 | 144 | | 参数名字 | 类型 | 必须 | 说明 | 145 | | ---------------- | ------ | ---- | -------------------------------------------------------------------------------------------------- | 146 | | access_token | string | 是 | 根据上面的获取 token | 147 | | bizRefundBatchId | int | 是 | 百度平台的订单号 | 148 | | isSkipAudit | int | 是 | 默认为 0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。 | 149 | | orderId | int | 是 | 百度平台的订单号 | 150 | | refundReason | string | 是 | 退款描述 | 151 | | refundType | int | 是 | 退款类型 1:用户发起退款;2:开发者业务方客服退款;3:开发者服务异常退款。百度小程序支付的平台公钥 | 152 | | tpOrderId | string | 是 | 自己平台订单号 | 153 | | userId | int | 是 | 用户 uid(不是自己平台 uid) | 154 | 155 | ```php 156 | $order = [ 157 | 'token' => 'abcd', 158 | 'bizRefundBatchId' => 123456,//百度平台订单号 159 | 'isSkipAudit' => 1, 160 | 'orderId' => 123456, 161 | 'refundReason' => '测试退款', 162 | 'refundType' => 2,// 163 | 'tpOrderId' => '123',//自己平台订单号 164 | 'userId' => 123, 165 | ]; 166 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order); 167 | ``` 168 | 169 | ### 百度小程序模版消息 170 | 171 | ```php 172 | $data = [ 173 | "touser_openId" => "", 174 | "template_id" => "", 175 | "page" => "pages/index/index", 176 | "subscribe_id" => '百度from组件subscribe-id 一致', 177 | "data" => json_encode([ 178 | 'keyword1' => ['value' => "第一个参数"], 179 | 'keyword2' => ['value' => "第二个参数"], 180 | 'keyword3' => ['value' => "第三个参数"], 181 | ]) 182 | ]; 183 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token); 184 | $data=[ 185 | "errno" => 0, 186 | "msg" => "success", 187 | "data" => array=> [ 188 | "msg_key" => 1663314134696897 189 | ] 190 | ] 191 | ``` 192 | 193 | # 抖音小程序 194 | 195 | ### Config 196 | 197 | | 参数名字 | 类型 | 必须 | 说明 | 198 | | ----------- | ------ | ---- | --------------------------------- | 199 | | token | string | 是 | 担保交易回调的 Token(令牌) | 200 | | salt | string | 是 | 担保交易的 SALT | 201 | | merchant_id | string | 是 | 担保交易的商户号 | 202 | | app_id | int | 是 | 小程序的 APP_ID | 203 | | secret | string | 是 | 小程序的 APP_SECRET | 204 | | notify_url | string | 是 | 支付回调 url | 205 | | settle_url | string | 否 | 分账回调 url,没有默认支付回调 url | 206 | 207 | ### Token 208 | 209 | ```php 210 | $PayName='Byte';//驱动 211 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken(); 212 | ``` 213 | 214 | | 返回参数 | 类型 | 必须 | 说明 | 215 | | ------------ | ------ | ---- | ---------------------- | 216 | | expires_in | string | 是 | 凭证有效时间,单位:秒 | 217 | | access_token | string | 是 | 获取到的凭证 | 218 | 219 | ### Openid 220 | 221 | ```php 222 | $PayName='Byte';//设置驱动 223 | $code=""; 224 | $anonymous_code="";//可以不传 225 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code,$anonymous_code); 226 | ``` 227 | 228 | | 返回参数 | 类型 | 必须 | 说明 | 229 | | ----------- | ------ | ---- | ----------- | 230 | | session_key | string | 是 | session_key | 231 | | openid | string | 是 | 用户 openid | 232 | | unionid | string | 是 | unionid | 233 | 234 | ### 解密手机号 235 | 236 | ```php 237 | $PayName='Baidu';//设置驱动 238 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData); 239 | echo $phone['phoneNumber']; 240 | ``` 241 | 242 | ### 订单查询 243 | 244 | ```php 245 | $PayName='Byte';//设置驱动 246 | $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config); 247 | $data = $Baidu->findOrder("订单号"); 248 | ``` 249 | 250 | ### 分账 251 | 252 | | 参数名字 | 类型 | 必须 | 说明 | 253 | | ------------- | ------ | ---- | ------------------------------ | 254 | | out_order_no | string | 是 | 平台订单号 | 255 | | out_settle_no | string | 是 | 自定义订单号 | 256 | | settle_desc | int | 是 | 分账描述 | 257 | | cp_extra | string | 是 | 开发者自定义字段,回调原样回传 | 258 | 259 | ```php 260 | $PayName='Byte';//设置驱动 261 | $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config); 262 | $data = $Baidu->settle($order); 263 | ``` 264 | 265 | ### 退款 266 | 267 | | 参数名字 | 类型 | 必须 | 说明 | 268 | | ------------- | ------ | ---- | ------------ | 269 | | out_order_no | string | 是 | 平台订单号 | 270 | | out_refund_no | int | 是 | 自定义订单号 | 271 | | reason | int | 是 | 退款说明 | 272 | | refund_amount | string | 是 | 退款金额 | 273 | 274 | ```php 275 | $order = [ 276 | 'out_order_no' => '', 277 | 'out_refund_no' => time() . 'refund', 278 | 'reason' => '就想退款,咋滴', 279 | 'refund_amount' => 1, //退款金额 280 | ]; 281 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order); 282 | //返回 [err_no] => 1 283 | // [err_tips] => 成功 284 | // [refund_no] => 1212 285 | ``` 286 | 287 | ### 模版消息 288 | 289 | ```php 290 | $data = [ 291 | 'tpl_id' => "模版id", 292 | "open_id" => $parm['openid'], 293 | 'data' => [ 294 | '律师' => "张三", 295 | "回复时间" => date('Y-m-d H:i:s', time()), 296 | "回复内容" => "我回复你啦", 297 | ], 298 | "page" => "pages/index/index", 299 | ]; 300 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token); 301 | 302 | ``` 303 | 304 | # 微信小程序 305 | 306 | ### Config 307 | 308 | | 参数名字 | 类型 | 必须 | 说明 | 309 | | ---------- | ------ | ---- | -------------------------------------------------------- | 310 | | appid | int | 是 | 小程序 appid | 311 | | secret | int | 是 | 小程序 secret | 312 | | mch_id | string | 是 | 商户 mch_id | 313 | | mch_key | string | 是 | 商户 mch_key | 314 | | notify_url | string | 是 | 异步地址 | 315 | | cert_pem | string | 是 | cert_pem 证书 | 316 | | key_pem | string | 是 | key_pem 证书 | 317 | | trade_type | string | 是 | 默认为:JSAPI。MWEB:代表微信 H5 、JSAPI:公众号或小程序 | 318 | 319 | ### Token 320 | 321 | ```php 322 | $PayName='Weixin';//驱动 323 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken(); 324 | ``` 325 | 326 | | 返回参数 | 类型 | 必须 | 说明 | 327 | | ------------ | ------ | ---- | ---------------------- | 328 | | expires_in | string | 是 | 凭证有效时间,单位:秒 | 329 | | access_token | string | 是 | 获取到的凭证 | 330 | 331 | ### Openid 332 | 333 | ```php 334 | $PayName='Weixin';//设置驱动 335 | $code=""; 336 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code); 337 | ``` 338 | 339 | | 返回参数 | 类型 | 必须 | 说明 | 340 | | ----------- | ------ | ---- | ----------- | 341 | | session_key | string | 是 | session_key | 342 | | openid | string | 是 | 用户 openid | 343 | | unionid | string | 是 | unionid | 344 | 345 | ### 微信解密手机号 346 | 347 | ```php 348 | $PayName='Weixin';//设置驱动 349 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData); 350 | echo $phone['phoneNumber']; 351 | ``` 352 | 353 | ### 微信订单查询 354 | 355 | ```php 356 | $PayName='Weixin';//设置驱动 357 | $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config); 358 | $data = $Baidu->findOrder("订单号"); 359 | ``` 360 | 361 | ### 微信退款 362 | 363 | | 参数名字 | 类型 | 必须 | 说明 | 364 | | ------------- | ------ | ---- | ------------ | 365 | | out_trade_no | string | 是 | 平台订单号 | 366 | | out_refund_no | string | 是 | 自定义订单号 | 367 | | refund_fee | int | 是 | 退款金额 | 368 | | total_fee | int | 是 | 订单金额 | 369 | | refund_desc | string | 是 | 退款原因 | 370 | 371 | ```php 372 | $order = [ 373 | 'out_trade_no' => '123', 374 | 'total_fee' => 0.01, 375 | 'out_refund_no' => time(), 376 | 'refund_fee' => 0.01, 377 | ]; 378 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order); 379 | ``` 380 | 381 | ### 微信小程序模版消息 382 | 383 | ```php 384 | $data = [ 385 | "touser" => "", 386 | "template_id" => "", 387 | "page" => "pages/index/index", 388 | "miniprogram_state" => "developer", 389 | "lang" => "zh_CN", 390 | "data" => [ 391 | 'thing6' => ['value' => "第一个参数{{thing6.DATA}}"], 392 | 'thing7' => ['value' => "第二个参数{{thing7.DATA}}"], 393 | 'time8' => ['value' => "第三个参数{{time8.DATA}}"], 394 | ], 395 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token); 396 | $data=[ 397 | "errcode" => 0 398 | "errmsg" => "ok" 399 | "msgid" => 123456 400 | ] 401 | ``` 402 | 403 | # 支付宝小程序 404 | 405 | > 使用密钥进行签名解密,没有使用证书签名解密。 406 | 407 | > 订单查询、退款、参数设置可以设置其他,具体看文档。 408 | 409 | > 返回值 看官方文档,每个返回值都不一样,自行判断,如 openid 返回[alipay_system_oauth_token_response] 退款返回[alipay_trade_create_response] 410 | 411 | ### Config 412 | 413 | | 参数名字 | 类型 | 必须 | 说明 | 414 | | ---------- | ------ | ---- | ---------------------------- | 415 | | appid | string | 是 | 小程序 appid | 416 | | secret | string | 是 | 小程序 AES 用于手机号解密 | 417 | | privateKey | string | 是 | 应用私钥(开发工具生成) | 418 | | publicKey | string | 是 | 支付宝公钥(支付宝后台下载) | 419 | | notify_url | string | 是 | 异步回调地址 | 420 | 421 | ### Openid 422 | 423 | > getOpenid 获取支付宝的用户 user_id 类似于微信的 openid 424 | 425 | ```php 426 | $PayName='Ali';//设置驱动 427 | $code=""; 428 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code); 429 | //返回参数 430 | $data = array( 431 | [alipay_system_oauth_token_response] => Array 432 | ( 433 | [access_token] => 123 434 | [alipay_user_id] => 123 435 | [auth_start] => 2023-03-26 20:56:36 436 | [expires_in] => 1296000 437 | [re_expires_in] => 2592000 438 | [refresh_token] => auth 439 | [user_id] => 123 440 | ) 441 | [sign] => 442 | ) 443 | ``` 444 | 445 | ### 支付宝小程序解密手机号 446 | 447 | ```php 448 | $PayName='Ali';//设置驱动 449 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData); 450 | echo $phone['mobile']; 451 | ``` 452 | 453 | ### 支付宝小程序订单查询 454 | 455 | ```php 456 | $PayName='Ali';//设置驱动 457 | $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config); 458 | $data = $Baidu->findOrder(['out_trade_no' => '1679838318']); 459 | ``` 460 | 461 | ### 支付宝小程序退款 462 | 463 | | 参数名字 | 类型 | 必须 | 说明 | 464 | | ------------- | ------ | ---- | ---------- | 465 | | out_trade_no | string | 是 | 平台订单号 | 466 | | refund_amount | int | 是 | 退款金额 | 467 | 468 | ```php 469 | $orders = [ 470 | 'out_order_no' => $order['out_order_no'], 471 | 'refund_amount' => $order['refund_amount'], 472 | ]; 473 | $PayName='Ali';//设置驱动 474 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order); 475 | ``` 476 | 477 | ### 支付宝小程序模版消息 478 | 479 | 模版消息设置比较麻烦。需要先到开发平台添加进入小程序进行产品绑定,在去商家平台设置[文档](https://opendocs.alipay.com/b/03ksho) 480 | 481 | ```php 482 | $data = [ 483 | 'to_user_id' => '用户uid', 484 | 'user_template_id' => '模版id', 485 | 'page' => 'pages/index/index', 486 | 'data' => json_encode([ 487 | 'keyword1' => ['value' => '1'], 488 | 'keyword2' => ['value' => '2'], 489 | 'keyword3' => ['value' => '3'], 490 | ]), 491 | ]; 492 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token); 493 | ``` 494 | 495 | # 快手小程序 496 | 497 | ### Token 498 | 499 | ```php 500 | $PayName='Kuaishou';//设置驱动 501 | $code=""; 502 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getToken(); 503 | ``` 504 | 505 | ### Config 506 | 507 | | 参数名字 | 类型 | 必须 | 说明 | 508 | | ---------- | ------ | ---- | ----------------------------------- | 509 | | app_id | int | 是 | 小程序 appid | 510 | | app_secret | int | 是 | 小程序 secret | 511 | | notify_url | string | 是 | 回调地址 | 512 | | settle_url | string | 是 | 结算回调地址,没有就默认 notify_url | 513 | | type | int | 是 | 类目 | 514 | 515 | ### Openid 516 | 517 | ```php 518 | $PayName='Kuaishou';//设置驱动 519 | $code=""; 520 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->getOpenid($code); 521 | ``` 522 | 523 | | 返回参数 | 类型 | 必须 | 说明 | 524 | | ----------- | ------ | ---- | ------------- | 525 | | session_key | string | 是 | session_key | 526 | | openid | string | 是 | 用户 open_id | 527 | | result | string | 是 | 状态 1 是成功 | 528 | 529 | ### 快手解密手机号 530 | 531 | ```php 532 | $PayName='Kuaishou';//设置驱动 533 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->decryptPhone($session_key, $iv, $encryptedData); 534 | echo $phone['phoneNumber']; 535 | ``` 536 | 537 | ### 快手订单查询 538 | 539 | ```php 540 | $PayName='Kuaishou';//设置驱动 541 | $Baidu = \Applet\Pay\Factory::getInstance($payName)->init($config); 542 | $data = $Baidu->findOrder("订单号",$access_token); 543 | ``` 544 | 545 | ### 快手退款 546 | 547 | | 参数名字 | 类型 | 必须 | 说明 | 548 | | ------------- | ------- | ---- | ------------ | 549 | | out_trade_no | string | 是 | 平台订单号 | 550 | | out_refund_no | strging | 是 | 自定义订单号 | 551 | | refund_amount | int | 是 | 退款金额 | 552 | | reason | string | 是 | 退款原因 | 553 | | access_token | string | 是 | access_token | 554 | | attach | string | 否 | 自定义 | 555 | 556 | ```php 557 | $orders = [ 558 | 'out_order_no' => $order['out_order_no'], 559 | 'out_refund_no' => $order['out_refund_no'], 560 | 'reason' => $order['reason'], 561 | 'attach' => $order['attach'], 562 | ]; 563 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->applyOrderRefund($order); 564 | ``` 565 | 566 | ### 快手结算 567 | 568 | | 参数名字 | 类型 | 必须 | 说明 | 569 | | ------------- | ------ | ---- | ------------ | 570 | | out_order_no | string | 是 | 平台订单号 | 571 | | out_settle_no | string | 是 | 自定义订单号 | 572 | | reason | string | 是 | 退款原因 | 573 | | access_token | string | 是 | access_token | 574 | | attach | string | 否 | 自定义 | 575 | 576 | ```php 577 | //注意 需要设置回调 notify_url 在config 设置 settle_url 如果没有 默认为 notify_url 578 | $orders = [ 579 | 'out_order_no' => $order['out_order_no'], 580 | 'out_settle_no' => $order['out_settle_no'], 581 | 'reason' => $order['reason'], 582 | 'attach' => $order['attach'], 583 | ]; 584 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->settle($order,$access_token); 585 | ``` 586 | 587 | ### 订单信息同步 588 | 589 | | 参数名字 | 类型 | 必须 | 说明 | 590 | | -------------------- | ------ | ---- | ------------------------ | 591 | | out_biz_order_no | string | 是 | 展示在用户端的唯一订单号 | 592 | | out_order_no | string | 是 | 小程序预下单支付订单号 | 593 | | open_id | string | 是 | 订单对应的用户 open id | 594 | | order_create_time | string | 是 | 订单创建时间 | 595 | | order_status | string | 否 | 订单状态 | 596 | | order_path | string | 是 | 小程序路径 | 597 | | product_cover_img_id | string | 是 | 图片 id | 598 | 599 | ```php 600 | 601 | $order = [ 602 | 'out_biz_order_no' => '', 603 | 'out_order_no' => '', 604 | 'open_id' => '', 605 | 'order_create_time' => time(), 606 | 'order_status' => 6, 607 | 'order_path' => '', 608 | 'product_cover_img_id' =>'', 609 | ]; 610 | $data = \Applet\Pay\Factory::getInstance($PayName)->init($config)->synchronousOrder($order, $token); 611 | ``` 612 | 613 | ### 图片上传(订单信息同步) 614 | 615 | ```php 616 | $data = \Applet\Pay\Factory::getInstance($PayName)->init($config)->imgUpload('图片路径', $token); 617 | ``` 618 | 619 | ### 快手小程序模版消息 620 | 621 | ```php 622 | $data = [ 623 | "open_id" => "", 624 | "tpl_id" => "", 625 | "page" => "pages/index/index", 626 | "data" => [ 627 | 'key1' => "第一个", 628 | 'key2' => "第二个", 629 | 'key3' => "第三个", 630 | ] 631 | ]; 632 | $data= \Applet\Pay\Factory::getInstance($PayName)->init($config)->sendMsg($data,$token); 633 | $data=[ 634 | "err_no" => 1001, 635 | "err_tips" => "该用户未订阅" 636 | ] 637 | ``` 638 | 639 | # 微信 APP 640 | 641 | ### Config 642 | 643 | | 参数名字 | 类型 | 必须 | 说明 | 644 | | ---------- | ------ | ---- | --------------- | 645 | | appid | int | 是 | 开发平台 appid | 646 | | secret | int | 是 | 开放平台 secret | 647 | | mch_id | string | 是 | 商户 mch_id | 648 | | mch_key | string | 是 | 商户 mch_key | 649 | | trade_type | string | 是 | APP | 650 | | notify_url | string | 是 | 异步地址 | 651 | 652 | # 异步通知 653 | 654 | ## 抖音 655 | 656 | ```php 657 | $pay = \Applet\Pay\Factory::getInstance('Byte')->init($config); 658 | $status = $pay->notifyCheck(); //验证 659 | if ($status) { 660 | $orderSn = $pay->getNotifyOrder(); //订单数据$orderSn['msg']['cp_orderno'] $orderSn['msg']['seller_uid'] 661 | switch ($orderSn['type']) { 662 | case 'payment': // 支付相关回调 663 | /** 664 | *业务处理 665 | */ 666 | echo json_encode(['err_no' => 0, 'err_tips' => 'success']);exit; // 操作成功需要给头条返回的信息 667 | break; 668 | case 'refund': // 退款相关回调 669 | /** 670 | *业务处理 671 | */ 672 | echo json_encode(['err_no' => 0, 'err_tips' => 'success']);exit; // 操作成功需要给头条返回的信息 673 | break; 674 | case 'settle': // 分账相关回调 675 | /** 676 | *业务处理 677 | */ 678 | echo json_encode(['err_no' => 0, 'err_tips' => 'success']);exit; // 操作成功需要给头条返回的信息 679 | break; 680 | default: // 未知数据 681 | return '数据异常'; 682 | } 683 | } 684 | ``` 685 | 686 | ## 微信回调(通用微信 H5 支付、小程序、微信公众号) 记得改 config 配置 687 | 688 | ```php 689 | $pay = \Applet\Pay\Factory::getInstance('Weixin')->init($config); 690 | $status = $pay->notifyCheck();//验证 691 | if($status){ 692 | $order = $pay->getNotifyOrder();//订单数据 693 | //$order['out_trade_no']//平台订单号 694 | //$order['transaction_id']//微信订单号 695 | echo 'success';exit; 696 | } 697 | ``` 698 | 699 | ## 百度小程序回调 700 | 701 | ```php 702 | $pay = \Applet\Pay\Factory::getInstance('Baidu')->init($config); 703 | $status = $pay->notifyCheck();//验证 704 | if($status){ 705 | $order = $pay->getNotifyOrder(); 706 | //$order['tpOrderId'] 707 | //$order['orderId'] 708 | //$order['userId'] 709 | echo 'success';exit; 710 | } 711 | ``` 712 | 713 | ## 快手小程序 714 | 715 | ```php 716 | $pay = \Applet\Pay\Factory::getInstance('Kuaishou')->init($config); 717 | $status = $pay->notifyCheck(); //验证 718 | if ($status) { 719 | $order = $pay->getNotifyOrder(); //订单数据 720 | //$order['data']['out_order_no']//平台订单号 721 | echo json_encode(['result' => 1, 'message_id' => $order['message_id']]);exit; 722 | } 723 | ``` 724 | 725 | ## 支付宝小程序 726 | 727 | ```php 728 | $pay = \Applet\Pay\Factory::getInstance('Ali')->init($config); 729 | $status = $pay->notifyCheck(); //验证 730 | if ($status) { 731 | $order = $pay->getNotifyOrder(); //订单数据 732 | //$order['out_trade_no']//平台订单号 733 | } 734 | ``` 735 | # 感谢赞助 736 | image 737 | image 738 | --------------------------------------------------------------------------------