支付demo1

Posted liyanxi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了支付demo1相关的知识,希望对你有一定的参考价值。

<?php
namespace AppHttpControllersFrontEnd;

use AppHttpControllersController;
//use AppHttpRequestsRequest;
use AppModelsMDebitLog;
use AppModelsMLog;
use AppModelsMUser;
use AppModelsMWallet;
use AppModelsMWithdrawLog;
use AppUtilsalipaysdkaopAopClient;
use AppUtilsalipaysdkaop
equestAlipayTradeWapPayRequest;
use IlluminateHttpRequest;

class PayController extends Controller{

    //支付宝
    public static $GATEWAY_URL = "https://openapi.alipay.com/gateway.do";  //网关
    public static $APP_ID = "2018101861687684";
    public static $RSA_PRIVATE_KEY = ‘MSSSIIEpAIBAAKCAQEAsEH/DTTWjryQhRV3FybaHodZuMWActjPWswkaviaHkXhHjBiMm+Pi4LSxidH572XXIYP8nXx1DKi7LrGFYatftLJzKyjjX379Pkzf+a0CNtNo7pIbiGDQeN0qT0Hll32V1JlzkoZPthqQRN6P6tSqqf0xjXs+yzv/oCAqZeoMEPumy/sOu1Sd2x5KL7mBrvZ7PC8+o+48KrpfLb2Vv8mNvQAxcnzFPJA8rPaTxhem83cccdazULnrdx6okoJnDlJGul7HdG27GavQH90tSdpkeUYSUOzVsBkNuOUfHqu6A/VXREmNuPoN7GKsv/mbpP4HQ130WEQTWRbVv7kr5IgBwIDAQABAoIBAD+P7TyD+4QJ+EwmC4Zr2mj8Ap0hjEreaRijWdbBxEJ6jM5oQGFT3f4/tWcEL2gg9P7G0eVsJ0OQ5zRbvqdwpAyCU4feEjUqY7xaSfor5mzzOTJ8MTaWG1Gdhyqo+Z1+USH4cwJLsoL5ZIgHUCS50dv9KcZ5F/cUo4+yI7QFHwAYRhgHhaAZFW8jk0ZCFzwKDZxUSIkFiAW6Jp2pApDW9lg4f6pLIA2wA6Lvnx7umIVjEpIrAfzCqIEElGUswyvQbuwDxf0+rn9+uyel2yxYdyHJIcWfLDsXUe/n47fLvOXCr3O+VAc/Jji3QD1DAMnIu2adys/vG5pERXqxE1r8EoECgYEA3LHdZGtryo+TMjtiZZbrIE6nhlEwsiUJm4ULVZcqu0iV6t+y5aJXCwVhRJdGTLVjk/El4oC/24KFSNmBFBSXTXJaQ6pWdCQDGOUcmmkqQ7EGqJw1EYojL2zBP4/cNQ68YCJSOEgIoppX+VAmxXmpr3TDzYMyn7VR4c3nWCxM4ucCgYEAzHRMmTBg3fkgHObCwogFeuBGWDRdY/UXsWfqBFbJncjhU1QW+9kTK38bD2WnOZwc8bnT1hrwOAq0DSzhZFrmx2whv/b5EJYHfOXklncwsQsWrhS6uueXG4nAX16ejhwkMj2bmTBxBGiKGx5P+awAFhnxvQwmu4kamfSlchUYVeECgYEAzAW6L92G1soIQAXaHyR31XQhNvDT3byTtyw1oDiRjnW58lo/Hj8HzO56T1ix6rQ9jEUAyvZPZ3SwFvrMc23dugEfJTLRnai1HEyiNrVGFzIOf8142fAkOvGFbWdnIb2vtAfGjrU5FmktLxRD44dnsQZ3BQRmxnJvchpR5pd9tL0CgYEAyvD1x2j5/dt3QLjdwXJ63gkYSh1QRhPWPMZEx6HN5syqvKfPWJWULayxE4t3ffuzz00BNJjwsPAO4LUX1SFVycVPith/STNio1selywgLNww2wLAhx2yJCeLyB6Hi8/rLeNxO5GV3SZXT6u6/rz4KPf/uAMDv0rMGN16C89cpIECgYAY/zZr1ZMntxFDIV9XeE+v6Cm8MqJ6w9/YpqlsxmDVzDpdWL9aXyov2EA//1uPHXL5GdgkRKY0fS2OFrhl+8uhvGDMzvc4hLE0JKS4w7/a5mI4xuIGLYNgPQp/qG22JHsUz1H8B+322WM1H2cs4j166PnZcv6ZPpi7KnXp2rPwzA==‘;    public static $API_VERSION = ‘1.0‘;
    public static $SIGN_TYPE = ‘RSA2‘;
    public static $POST_CHARSET = ‘utf-8‘;
    public static $FORMAT = ‘json‘;
//    public static $ALIPAY_RSA_PUBLIC_KEY = ‘MSSSSIIEpAIBAAKCAQEAsEH/DTTWjryQhRV3FybaHodZuMWActjPWswkaviaHkXhHjBiMm+Pi4LSxidH572XXIYP8nXx1DKi7LrGFYatftLJzKyjjX379Pkzf+a0CNtNo7pIbiGDQeN0qT0Hll32V1JlzkoZPthqQRN6P6tSqqf0xjXs+yzv/oCAqZeoMEPumy/sOu1Sd2x5KL7mBrvZ7PC8+o+48KrpfLb2Vv8mNvQAxcnzFPJA8rPaTxhem83cccdazULnrdx6okoJnDlJGul7HdG27GavQH90tSdpkeUYSUOzVsBkNuOUfHqu6A/VXREmNuPoN7GKsv/mbpP4HQ130WEQTWRbVv7kr5IgBwIDAQABAoIBAD+P7TyD+4QJ+EwmC4Zr2mj8Ap0hjEreaRijWdbBxEJ6jM5oQGFT3f4/tWcEL2gg9P7G0eVsJ0OQ5zRbvqdwpAyCU4feEjUqY7xaSfor5mzzOTJ8MTaWG1Gdhyqo+Z1+USH4cwJLsoL5ZIgHUCS50dv9KcZ5F/cUo4+yI7QFHwAYRhgHhaAZFW8jk0ZCFzwKDZxUSIkFiAW6Jp2pApDW9lg4f6pLIA2wA6Lvnx7umIVjEpIrAfzCqIEElGUswyvQbuwDxf0+rn9+uyel2yxYdyHJIcWfLDsXUe/n47fLvOXCr3O+VAc/Jji3QD1DAMnIu2adys/vG5pERXqxE1r8EoECgYEA3LHdZGtryo+TMjtiZZbrIE6nhlEwsiUJm4ULVZcqu0iV6t+y5aJXCwVhRJdGTLVjk/El4oC/24KFSNmBFBSXTXJaQ6pWdCQDGOUcmmkqQ7EGqJw1EYojL2zBP4/cNQ68YCJSOEgIoppX+VAmxXmpr3TDzYMyn7VR4c3nWCxM4ucCgYEAzHRMmTBg3fkgHObCwogFeuBGWDRdY/UXsWfqBFbJncjhU1QW+9kTK38bD2WnOZwc8bnT1hrwOAq0DSzhZFrmx2whv/b5EJYHfOXklncwsQsWrhS6uueXG4nAX16ejhwkMj2bmTBxBGiKGx5P+awAFhnxvQwmu4kamfSlchUYVeECgYEAzAW6L92G1soIQAXaHyR31XQhNvDT3byTtyw1oDiRjnW58lo/Hj8HzO56T1ix6rQ9jEUAyvZPZ3SwFvrMc23dugEfJTLRnai1HEyiNrVGFzIOf8142fAkOvGFbWdnIb2vtAfGjrU5FmktLxRD44dnsQZ3BQRmxnJvchpR5pd9tL0CgYEAyvD1x2j5/dt3QLjdwXJ63gkYSh1QRhPWPMZEx6HN5syqvKfPWJWULayxE4t3ffuzz00BNJjwsPAO4LUX1SFVycVPith/STNio1selywgLNww2wLAhx2yJCeLyB6Hi8/rLeNxO5GV3SZXT6u6/rz4KPf/uAMDv0rMGN16C89cpIECgYAY/zZr1ZMntxFDIV9XeE+v6Cm8MqJ6w9/YpqlsxmDVzDpdWL9aXyov2EA//1uPHXL5GdgkRKY0fS2OFrhl+8uhvGDMzvc4hLE0JKS4w7/a5mI4xuIGLYNgPQp/qG22JHsUz1H8B+322WM1H2cs4j166PnZcv6ZPpi7KnXp2rPwzA==‘;
    public static $ALIPAY_RSA_PUBLIC_KEY  =‘MSSSIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjHqgY7To6AirhsUrBb8IihWUiciaAHQUksM02KCzuIxu4F8ZMLEE7fDvWYQrpJhasyoLDR6Q0FoU7TCFFvTDaSmdiziLThEKm0weQTARNzF5bwVVC4b6XIyuHIqje3O4Jr4bAbINVeZhh0yjmZxHV0ucqDqie9Re3vcffmR+CwkSIDhBkJoVHdgMjA3U4PdKWAu87Gke02FpSIIp2rHv0Xj5u7OteCzl068Zr7ERhSRbeNjVAQMxeo8Slk0LEZW6SWs9fh1j9DeiQDtgoo/eae8zoIxFsGR6/noghk+wVQajOQQrgYKcsR3LCGzVRnIXoBqbfG7MqxicUE/1xgyoKQIDAQAB‘;
    //微信
    public static $WX_APP_ID = "****"; //微信公众号APPid
    public static $WX_MCH_ID = "******";        //微信商家账号
    public static $WX_SECRET_KEY ="*******";
    //public static $WX_

    /**
     * 支付宝手机端在线支付
     */

    public function test(){

    }
//    public function aliPay($money,$no,$subject,$body){
    public function aliPay(){
        //构造参数
        $aop = new AopClient();
        //或者
        //引入sdk
        require_once "pay/alipaysdk/AopSdk.php";
        $aop = new AopClient();

        $aop->gatewayUrl = self::$GATEWAY_URL;
        $aop->appId = self::$APP_ID;
        $aop->rsaPrivateKey = self::$RSA_PRIVATE_KEY;
        $aop->apiVersion = self::$API_VERSION;
        $aop->signType = self::$SIGN_TYPE;
        $aop->postCharset= self::$POST_CHARSET;
        $aop->format= self::$FORMAT;
        $aop->alipayrsaPublicKey = self::$ALIPAY_RSA_PUBLIC_KEY;
        $request = new AlipayTradeWapPayRequest();
        //或者
        $request = new AlipayTradePagePayRequest();

        $request->setReturnUrl(route(‘web.alipay.return‘));
        $request->setNotifyUrl(route(‘web.alipay.notify‘));

        $money =0.01;
        $no=time().rand(1,100);
        $subject ="666";
        $body = ‘2220‘;

        $request->setBizContent(
            "{".""product_code":"QUICK_WAP_WAY",".
            ""out_trade_no":"$no",".
            ""subject":"$subject",".
            ""total_amount":"$money",".
            ""body":"$body",".
            ""timeout_express":"1m"".
            "}"
        );
        //请求
        $result = $aop->pageExecute ($request);
//        输出
        echo $result;
    }
    //支付宝同步通知
    public function aliReturn(){
        $aop = new AopClient();
        //或者  -- 引入sdk

        require_once "pay/alipaysdk/AopSdk.php";

        $aop->alipayrsaPublicKey = self::$ALIPAY_RSA_PUBLIC_KEY;
        //此处验签方式必须与下单时的签名方式一致
        $flag = $aop->rsaCheckV1($_GET, NULL, "RSA2");
        //验签通过后再实现业务逻辑,比如修改订单表中的支付状态。
        if ($flag){
            //跳转支付成功页面
            MLog::log("会员充值成功!");
            echo ‘充值成功‘;
            return redirect()->route(‘login.page‘);
        }else{
            //跳转支付失败页面
            echo ‘充值失败‘;
            return redirect()->route(‘login.page‘);
        }
    }
    //支付宝异步通知
    public function aliNotify(){
        $aop = new AopClient();
        $aop->alipayrsaPublicKey = self::$ALIPAY_RSA_PUBLIC_KEY;
        //此处验签方式必须与下单时的签名方式一致
        $flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
        //验签通过后再实现业务逻辑,比如修改订单表中的支付状态。
        /**
         * ①验签通过后核实如下参数out_trade_no、total_amount、seller_id
         * ②修改订单表
         **/
        //打印success,应答支付宝。必须保证本界面无错误。只打印了success,否则支付宝将重复请求回调地址。
        //echo ‘success‘;
        if ($flag){
            //交易状态
            MLog::log("管理员充值成功!");
            echo ‘success‘;
        }else{

            echo "fail";
        }
    }

    /**
     * 第三方微信支付
     * $no      订单号
     * $money   订单金额
     * $title   订单标题
     * $info    订单详情
     */
    public function wechatPay($no, $money, $title, $info){
//引入sdk
        require_once "pay/Wxpay/example/WxPay.Api.php";
        $notify = new NativePay();
        $input = new WxPayUnifiedOrder();
        $input->SetBody("test");//商品描述
        $input->SetAttach("test");//附加数据
        $input->SetOut_trade_no(‘123456789‘);//订单号唯一
        $input->SetTotal_fee("1");//商品价格
        $input->SetTime_start(date("YmdHis"));//开始时间
        $input->SetTime_expire(date("YmdHis", time() + 600)); //交易结束时间
        $input->SetNotify_url(route(‘web.wxpay.notify‘));//通知地址
        $input->SetTrade_type("NATIVE");//交易类型
        $input->SetProduct_id("123456789");//商品id
        $result = $notify->GetPayUrl($input);
        $url = $result["code_url"];
        return "http://paysdk.weixin.qq.com/example/qrcode.php?data=" . $url;
    }
    //回调函数
    public function wxNotify() {
        require_once "pay/Wxpay/example/WxPay.Api.php";
        //file_put_contents("/tmp/wechat.log",$GLOBALS[‘HTTP_RAW_POST_DATA‘]);
        try{
            $notify = new NativeNotifyCallBack();
            $notify->Handle(true);

        }catch(Exception $e){
            throw $e;
        }
    }

    /**
     * 微信h5在线支付
     * $openid 用户的openid
     */
//    public function wechatPay($money,$no){
    public function wechatPayH5(Request $request){
        header(‘content-type:text/html;charset=utf-8‘);
        $data[‘appid‘]= self::$WX_APP_ID;//商户的应用appid
        $data[‘mch_id‘]=self::$WX_MCH_ID;//商户ID
        $data[‘nonce_str‘]=$this->unicode();//unicode();//
        $data[‘body‘] = "智能名片充值系统";
        $money = 1; $no="dfasjsdooijdvoj123".time();
        $data[‘out_trade_no‘]="$no";//.time();//商户订单号
        $data[‘total_fee‘] = $money;//订单金额
        $data[‘spbill_create_ip‘] = $this->get_client_ip();//终端ip
        $data[‘notify_url‘] = route(‘web.wxpay.notify‘);//通知地址
        $data[‘trade_type‘] = ‘MWEB‘;//交易类型
        //$wap_url = ‘http://‘.$_SERVER[‘HTTP_HOST‘];
//        $data[‘scene_info‘] = ‘{"h5_info": {"type":"Wap","wap_url": "http://nizuishuai.iok.la","wap_name": "全民环保租车充值"}}‘;//场景信息
        $data[‘scene_info‘] = ‘{"h5_info": {"type":"Wap","wap_url": "http://yunhuijuke.com","wap_name": "智能名片充值系统"}}‘;//场景信息

        $sign = $this->getSign($data);
        $data[‘sign‘]= $sign;
        $xml=$this->arraytoxml($data);
        $url=‘https://api.mch.weixin.qq.com/pay/unifiedorder‘;
        $res=$this->curl($xml,$url);
        $result = $this->xmltoarray($res);
        if ($result[‘return_code‘] == ‘SUCCESS‘ && $result[‘result_code‘] == ‘SUCCESS‘){
            $url = $result[‘mweb_url‘];
            header("Location: $url");
            exit;
        } else{
            dump($result[‘return_msg‘]);
        }
    }
    /**
     * 微信通知
     */
    public function wxNotifyH5(){
        //get post data,May be due to the  different environments;
        $shuoming = $GLOBALS[‘HTTP_RAW_POST_DATA‘];
        $post_data = json_decode(json_encode(simplexml_load_string($GLOBALS[‘HTTP_RAW_POST_DATA‘], ‘SimpleXMLElement‘, LIBXML_NOCDATA)), true);
        //验签
        if ($this->checkSign($post_data)){
            //验签成功
            $array_data[‘out_trade_no‘] = $post_data[‘out_trade_no‘];//商户订单号
            $array_data[‘total_fee‘] = $post_data[‘total_fee‘];//订单金额
            $array_data[‘trade_state‘] = $post_data[‘result_code‘];//订单状态
            $array_data[‘transaction_id‘] = $post_data[‘transaction_id‘];//微信支付订单号
            //验证交易状态成功
            if ($array_data[‘trade_state‘] == "SUCCESS"){
                //验证订单状态金额是否正确
                $debit = MDebitLog::where(‘no‘,$array_data[‘out_trade_no‘])->first();
                if ($debit->statu==1 && $debit->money == $array_data[‘total_fee‘]/100){
                    //修改充值记录为已完成,增加用户现金币余额
                    $wallet = MWallet::where(‘uid‘,$debit->uid)->first();
                    $wallet->w1 += $debit->money;
                    $debit->statu = 2;
                    if ($wallet->save() && $debit->save()){
                        return true;
                    }
                }
            }
            echo ‘success‘;
        }else{
            //验签失败
            echo ‘fail‘;
        }
    }
    function unicode() {
        $str = uniqid(mt_rand(),1);
        $str=sha1($str);
        return md5($str);
    }
    function arraytoxml($data){
        $str=‘<xml>‘;
        foreach($data as $k=>$v) {
            $str.=‘<‘.$k.‘>‘.$v.‘</‘.$k.‘>‘;
        }
        $str.=‘</xml>‘;
        return $str;
    }
    function xmltoarray($xml) {

        libxml_disable_entity_loader(true);//禁止引用外部xml实体
        $xmlstring = simplexml_load_string($xml, ‘SimpleXMLElement‘, LIBXML_NOCDATA);
        $val = json_decode(json_encode($xmlstring),true);
        return $val;
    }
    function curl($param="",$url) {

        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();                                      //初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);                 //抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);                    //设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            //要求结果为字符串且输出到屏幕上

        curl_setopt($ch, CURLOPT_POST, 1);                      //post提交方式

        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);             // 增加 HTTP Header(头)里的字段 ---请求url中的参数
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        // 终止从服务端进行验证
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        $data = curl_exec($ch);                                 //运行curl
        //返回结果
        if($data){
            curl_close($ch);
            return $data;
        }
        else {
            $error = curl_errno($ch);
            echo "curl出错,错误码:$error"."<br>";
            curl_close($ch);
            return false;
        }
    }
    /**
     * 获取终端ip
     */
    public function get_client_ip(){
        $ip = ‘‘;
        if(isset($_SERVER[‘HTTP_X_FORWARDED_FOR‘])){
            $ip = $_SERVER[‘HTTP_X_FORWARDED_FOR‘];
        }elseif(isset($_SERVER[‘HTTP_CLIENT_IP‘])){
            $ip = $_SERVER[‘HTTP_CLIENT_IP‘];
        }else{
            $ip = $_SERVER[‘REMOTE_ADDR‘];
        }
        $ip_arr = explode(‘,‘, $ip);
        return $ip_arr[0];
    }

    /**
     * 获取签名
     */
    public function getSign($data){
        $secrect_key=self::$WX_SECRET_KEY;//
        $data=array_filter($data);
        ksort($data);
        $str=‘‘;
        foreach($data as $k=>$v) {
            $str.=$k.‘=‘.$v.‘&‘;
        }
        $str.=‘key=‘.$secrect_key;

        //进行签名
        return md5($str);
    }

    /**
     * 验签
     */
    public function checkSign($data)
    {
        $tmpData = $data;
        unset($tmpData[‘sign‘]);
        $sign = $this->getSign($tmpData);//本地签名
        if ($data[‘sign‘] == $sign) {
            return TRUE;
        }
        return FALSE;
    }


    //QQ登录
    public function QQlogin(Request $request) {
        //验证是否是QQ登录
        $code  =$request ->code;
        if (!empty($code)) {
            $url = "https://graph.qq.com/oauth2.0/token";
            $param[‘grant_type‘] = ‘authorization_code‘;
            $param[‘client_id‘] = "101513947";
            $param[‘client_secret‘] = "426d860fea56390ee64293631ba90fe1";
            $param[‘code‘] = $code;
            $param[‘redirect_uri‘]= "http://www.hnyhj.net/login";
            $param = http_build_query($param);
            $res = $this ->QQ_curl($param,$url);
//            此处得到 access_token
            $mm="access_token=B4DDFA6593CF6C6130708961B83C9E4F&expires_in=7776000&refresh_token=B2FCB0302D06D9CCD97FBA3DA7FA9FCE";


            https://graph.qq.com/user/get_user_info?access_token=B4DDFA6593CF6C6130708961B83C9E4F&oauth_consumer_key=101513947&openid=92ACC880BD4EAAA61A7244137ED2E31A
            return $res;
        }

    }
    /**
     * @param string $param 为 字符串  json_encode()后的 参数
     * @param $url
     * @return bool|mixed
     */
    function QQ_curl($param="", $url)
    {
        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();                                      //初始化curl
        curl_setopt($ch, CURLOPT_URL, $postUrl);                 //抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);                    //设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            //要求结果为字符串且输出到屏幕上

//        curl_setopt($ch, CURLOPT_POST, 1);                      //post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);             // 增加 HTTP Header(头)里的字段 ---请求url中的参数
//    改为get 取掉   curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        // 终止从服务端进行验证 ssl协议
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        $data = curl_exec($ch);                                 //运行curl
        //返回结果
        if ($data) {
            curl_close($ch);
            return $data;
        } else {
            $error = curl_errno($ch);
            echo "curl出错,错误码:$error" . "<br>";
            curl_close($ch);
            return false;
        }

    }


    /**
     * 支付宝提现
     */
    public function alipayTx($money,$no, $ali_no, $ali_name){
        //引入sdk
        require_once "pay/alipaysdk/AopSdk.php";
        $aop = new AopClient ();
        $aop->gatewayUrl = self::$GATEWAY_URL;
        $aop->appId = self::$APP_ID;
        $aop->rsaPrivateKey = self::$RSA_PRIVATE_KEY;
        $aop->alipayrsaPublicKey= self::$ALIPAY_RSA_PUBLIC_KEY;
        $aop->apiVersion = self::$API_VERSION;
        $aop->signType = self::$SIGN_TYPE;
        $aop->postCharset= self::$POST_CHARSET;
        $aop->format= self::$FORMAT;
        $request = new AlipayFundTransToaccountTransferRequest ();

        $request->setBizContent("{" .
            ""out_biz_no":"$no"," .
            ""payee_type":"ALIPAY_LOGONID"," .
            ""payee_account":"$ali_no"," .
            ""amount":"$money"," .
            ""payer_show_name":"弘商城提现"," .
            ""payee_real_name":"$ali_name"," .
            ""remark":"弘商城支付宝提现"" .
            "  }");
        $result = $aop->execute( $request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        $out_no = $result->$responseNode->out_biz_no;
        if(!empty($resultCode)&&$resultCode == 10000){
            //处理逻辑

            $this->data = true;
        } else {
            $this->data = false;
        }
        return $this->data;
    }

    /**
     * 微信提现
     */
    public function wechatTx($openid,$money,$realname,$no){
        header(‘content-type:text/html;charset=utf-8‘);
        $data[‘mch_appid‘]= self::$WX_APP_ID;//商户的应用appid
        $data[‘mchid‘]= self::$WX_MCH_ID;//商户ID
        $data[‘nonce_str‘]=$this->unicode();//unicode();//
        $data[‘partner_trade_no‘]="$no";//.time();//
        $data[‘openid‘]=$openid;//
        $data[‘check_name‘]=‘NO_CHECK‘;//
        $data[‘re_user_name‘]=$realname;//
        $data[‘amount‘]=floatval($money*100);//
        $data[‘desc‘]=‘用户提现‘;//
        $data[‘spbill_create_ip‘]=$_SERVER[‘SERVER_ADDR‘];//
        $secrect_key= self::$WX_SECRET_KEY;///
        $data=array_filter($data);
        ksort($data);
        $str=‘‘;
        foreach($data as $k=>$v) {
            $str.=$k.‘=‘.$v.‘&‘;
        }
        $str.=‘key=‘.$secrect_key;
        $data[‘sign‘]=md5($str);
        $xml=$this->arraytoxml($data);
        $url= self::$WX_URL;
        $res=$this->pem_curl($xml,$url);
        $return = $this->xmltoarray($res);
        if ($return[‘return_code‘] == ‘SUCCESS‘ && $return[‘result_code‘] == ‘SUCCESS‘){
            //处理逻辑
            return true;
        }else{
            return false;
        }
    }
    //需要证书的curl
    function pem_curl($param="",$url) {
        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();                                      //初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);                 //抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);                    //设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);                      //post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);           // 增加 HTTP Header(头)里的字段
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        // 终止从服务端进行验证
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch,CURLOPT_SSLCERT,app_path().‘/Utils/Wxpay/apiclient_cert.pem‘); //这个是证书的位置
        curl_setopt($ch,CURLOPT_SSLKEY,app_path().‘/Utils/Wxpay/apiclient_key.pem‘); //这个也是证书的位置
        $data = curl_exec($ch);                                 //运行curl
        //返回结果
        if($data){
            curl_close($ch);
            return $data;
        }
        else {
            $error = curl_errno($ch);
            echo "curl出错,错误码:$error"."<br>";
            curl_close($ch);
            return false;
        }
    }
}

  

以上是关于支付demo1的主要内容,如果未能解决你的问题,请参考以下文章

微信支付的开发

在 android 中使用 Telr 支付网关时上下文为空

demo1---相册

44. CSRF 攻击与防御

C代码编译成可执行程序的过程

webpack初学笔记 之 小案例篇demo1