这篇文章给大家介绍如何是PHP实现微信支付功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
import("wxpay.lib.AppPay#Config", EXTEND_PATH, ".php"); import("wxpay.lib.WxPay#Api", EXTEND_PATH, ".php"); //$this->weixinpay(); $config = new \AppPayConfig(); //订单号 $appId = $config->GetAppId(); $key = $config->GetKey(); $money = 0.01 * 100; $orderSn = 'M201810241754107557';//订单号; $curTime = time(); $input = new \WxPayUnifiedOrder(); $input->SetBody("用户红包"); $input->SetOut_trade_no($orderSn); $input->SetTotal_fee($money); $input->SetTrade_type("APP"); $unifiedOrder = \WxPayApi::unifiedOrder($config, $input); if ($unifiedOrder['result_code'] == 'SUCCESS' && $unifiedOrder['return_code'] == 'SUCCESS') { /*$unifiedOrder 组成: * ["appid"] => string(18) "wx2xxxx49" ["mch_id"] => string(10) "1xxxxxx01" ["nonce_str"] => string(16) "1GnEUXTuTcFtJVtb" ["prepay_id"] => string(36) "wx241933xxx68fa24ece70611692955" ["result_code"] => string(7) "SUCCESS" ["return_code"] => string(7) "SUCCESS" ["return_msg"] => string(2) "OK" ["sign"] => string(32) "7903xxxxx4710E460CB156" ["trade_type"] => string(3) "APP"*/ $curTime = time(); // 第一部分 $wxpayResult = new \WxPayResults(); $wxpayResult->SetData('appid', $unifiedOrder['appid']); $wxpayResult->SetData('partnerid', $unifiedOrder['mch_id']); $wxpayResult->SetData('prepayid', $unifiedOrder['prepay_id']); $wxpayResult->SetData('noncestr', $unifiedOrder['nonce_str']); $wxpayResult->SetData('timestamp',$curTime); $wxpayResult->SetData('package',"Sign=WXPay"); $wxpayResult->SetData('sign',""); $wxpayResult->SetSign($config); $data = $wxpayResult->GetValues(); // 第二部分 $data['appid'] = $unifiedOrder['appid']; $data['partnerid'] = $unifiedOrder['mch_id']; $data['prepayid'] = $unifiedOrder['prepay_id']; $data['noncestr'] = $unifiedOrder['nonce_str'];; $data['timestamp'] = $curTime; $data['package'] = "Sign=WXPay"; $data['sign'] = $this->wxappPaySign($key, $data);//$unifiedOrder['sign'];//签名,具体签名方案参见微信公众号支付帮助文档; $this->returnSuccess($data); } else { Log::write(var_export($unifiedOrder, true)); $this->returnError(300, '微信支付失败'); } private function wxappPaySign($key,$parameters) { $sign = md5(sprintf("appid=%s&noncestr=%s&package=%s&partnerid=%s&prepayid=%s×tamp=%s&key=%s", $parameters['appid'], $parameters['noncestr'], $parameters['package'], $parameters['partnerid'], $parameters['prepayid'], $parameters['timestamp'], $key)); return strtoupper($sign); }
php是一个嵌套的缩写名称,是英文超级文本预处理语言,它的语法混合了C、Java、Perl以及php自创新的语法,主要用来做网站开发,许多小型网站都用php开发,因为php是开源的,从而使得php经久不衰。
关于如何是PHP实现微信支付功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。