• Welcome to Journal web site.

我是 PHP 程序员

- 开发无止境 -

Next
Prev

小程序与php 实现微信支付_admin1008611的博客

Data: 2012-10-14 15:54:49Form: JournalClick: 0

小程序访问地址:

payfee.php:

include 'WeixinPay.php';

$appid='';

$openid= $_GET['id'];

$mch_id='';

$key='';

$out_trade_no = $mch_id. time();

$total_fee = $_GET['fee'];

if(empty($total_fee)) //押金

{

    $body = "充值押金";

    $total_fee = floatval(99*100);

}

 else {

     $body = "充值余额";

     $total_fee = floatval($total_fee*100);

 }

$weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee);

$return=$weixinpay->pay();

 

echo json_encode($return);

 

 

WeixinPay.php:

<?php

 

 

/*

 * 小程序微信支付

 */

 

 

class WeixinPay {

 

 

    protected $appid;

    protected $mch_id;

    protected $key;

    protected $openid;

    protected $out_trade_no;

    protected $body;

    protected $total_fee;

            function __construct($appid, $openid, $mch_id, $key,$out_trade_no,$body,$total_fee) {

        $this->appid = $appid;

        $this->openid = $openid;

        $this->mch_id = $mch_id;

        $this->key = $key;

        $this->out_trade_no = $out_trade_no;

        $this->body = $body;

        $this->total_fee = $total_fee;

    }

 

 

    public function pay() {

        //统一下单接口

        $return = $this->weixinapp();

        return $return;

    }

 

 

    //统一下单接口

    private function unifiedorder() {

        $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';

        $parameters = array(

            'appid' => $this->appid, //小程序ID

Name:
<提交>