首页 > 开发 > PHP > 正文

php微信支付之APP支付方法

2024-05-04 22:38:57
字体:
来源:转载
供稿:网友

本文实例讲述了微信开放平台移动应用集成微信支付功能。分享给大家供大家参考。具体分析如下:

WechatAppPay文件代码如下:
代码如下:
<?php
namespace common/services/WechatPay;
class WechatAppPay extends WechatPayBase
{
    //package参数
    public $package = [];
    //异步通知参数
    public $notify = [];
    //推送预支付订单参数
    protected $config = [];
    //存储access token和获取时间的文件
    protected $file;
    //access token
    protected $accessToken;
    //取access token的url
    const ACCESS_TOKEN_URL = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s';
    //生成预支付订单提交地址
    const POST_ORDER_URL = 'https://api.weixin.qq.com/pay/genprepay?access_token=%s';
    public function __construct()
    {
        $this->file = __DIR__ . '/payAccessToken.txt';
    }
    /**
     * 创建APP支付最终返回参数
     * @throws /Exception
     * @return multitype:string NULL
     */
    public function createAppPayData()
    {
        $this->generateConfig();
        $prepayid = $this->getPrepayid();
        try{
            $array = [
                'appid' => $this->appid,
                'appkey' => $this->paySignkey,
                'noncestr' => $this->getRandomStr(),
                'package' => 'Sign=WXPay',
                'partnerid' => $this->partnerId,
                'prepayid' => $prepayid,
                'timestamp' => (string)time(),
            ];
            $array['sign'] = $this->sha1Sign($array);

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表