您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

基于ThinkPay的微信支付(JSAPI)

2024/3/14 6:29:02发布27次查看
基于thinkpay的微信支付,摒弃腾讯自己搞的sdk,封装的太复杂了,直接基于thinkpay一个文件实现微信支付,加群130747567。
基于thinkpay的微信支付,摒弃腾讯自己搞的sdk,封装的太复杂了,直接基于thinkpay一个文件实现微信支付,加群130747567。
/**
 * 微信支付驱动
 */
class wxpay extends \addons\pay\thinkpay\pay\pay {
    protected $gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
    protected $orderquery = 'https://api.mch.weixin.qq.com/pay/orderquery';
    protected $config  = array(
        'appid'     => '',
        'appsecret' => '',
        'mchid'     => '',
        'key'       => ''
    );
public function check() {
        if (!$this->config['appid'] || !$this->config['appsecret'] || !$this->config['mchid'] || !$this->config['key']) {
            e(微信支付设置有误!);
        }
        return true;
    }
public function buildrequestform($pay_data) {
        // 获取用户openid,微信公众号jsapi支付必须
        $openid = $this->getopenid();
        $param = array(
            'appid'            => $this->config['appid'],
            'mch_id'           => $this->config['mchid'],
            'nonce_str'        => $this->getnoncestr(),
            'body'             => $pay_data['body'],
            'out_trade_no'     => $pay_data['out_trade_no'],
            'total_fee'        => $pay_data['money'] * 100,
            'spbill_create_ip' => $_server['remote_addr'],
            'notify_url'       => $this->config['notify_url'],
            'trade_type'       => 'jsapi',
            'openid'           => $openid,
        );
// 签名
        $param['sign'] = $this->makesign($param);
        $xml_param = $this->toxml($param);
        $result = $this->fromxml($this->postxmlcurl($xml_param, $this->gateway));
        if($result['return_code'] === 'success'){
            if ($this->checksign($result)) {
                $jsapiparameters = $this->getjsapiparameters($result);
                $pay_page =
微信支付
该笔订单支付金额为{$pay_data['money']}元
立即支付
eof;
                return $pay_page;
            }
        } else {
            e(微信订单错误! . $result['return_msg']);
        }
    }
}
ad:真正免费,域名+虚机+企业邮箱=0元
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product