/** * 设置订单 */ public function setOrder(Order $order) { if (null !== $order) { try { $order->checkParams(); } catch (Exception $e) { throw new PaymentException($e->getMessage()); } if (!$order->hasParams('nonce_str')) { $order->nonce_str(Util::randomString()); } if (!$order->hasParams('spbill_create_ip')) { $order->spbill_create_ip(Util::clientIP()); } if (!$order->hasParams('trade_type')) { if (!$order->hasParams('openid')) { throw new PaymentException('openid is required'); } $order->trade_type('JSAPI'); } $this->order = $order; } }
/** * 第 1 步:定义商户 * 设置商户证书路径请使用 setClientCert/setClientKey * $business->setClientCert('/your/path/to/apiclient_cert.pem'); * $business->setClientKey('/your/path/to/apiclient_key.pem'); */ $business = new Business(); $business->appid(APPID); $business->appsecret(APPSECRET); $business->mch_id(MCHID); $business->mch_key(MCHKEY); // print_r($business->getParams()); /** * 第 2 步:定义订单 */ $order = new Order(); $order->body('iphone 6 plus'); $order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999)); $order->total_fee('1'); // $order->openid($_SESSION['openid']); $order->openid('oWY-5jjLjo7pYUK86JPpwvcnF2Js'); $order->notify_url('http://code.1999.me/Wechat/example/payment_notify.php'); // print_r($order->getParams()); /** * 第 3 步:统一下单 */ $unifiedorder = new Unifiedorder(); $unifiedorder->setBusiness($business); $unifiedorder->setOrder($order); /** * 第 4 步:生成支付配置文件
// "openid" => "oWY-5jjLjo7pYUK86JPpwvcnF2Js", // "mch_id" => "1241642202", // "is_subscribe" => "Y", // "nonce_str" => "fhKb6Fkzm3UJrX95", // "product_id" => "2015080618052364076", // "sign" => "1ED0F1A052F5212009E7C5DB89C57789" // ); /** * 统一下单 */ $business = new Business(); $business->appid(APPID); $business->appsecret(APPSECRET); $business->mch_id(MCHID); $business->mch_key(MCHKEY); $order = new Order(); $order->body('iphone 6 plus'); $order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999)); $order->total_fee('1'); $order->openid($request['openid']); $order->notify_url('Your notify url'); $unifiedorder = new Unifiedorder($business, $order); $response = $unifiedorder->getResponse(); /** * 响应订单 */ $params = array('return_code' => 'SUCCESS', 'result_code' => 'SUCCESS', 'return_msg' => 'return message', 'appid' => $request['appid'], 'err_code_des' => 'err code description', 'mch_id' => $request['mch_id'], 'nonce_str' => $request['nonce_str'], 'prepay_id' => $response['prepay_id']); $signGenerator = new SignGenerator($params); $signGenerator->onSortAfter(function ($that) { $that->addParams('key', MCHKEY); });
$jssdkConfig = $o->getConfig(array('chooseWXPay'), true); /** * 第 1 步:定义商户 * 设置商户证书路径请使用 setClientCert/setClientKey * $business->setClientCert('/your/path/to/apiclient_cert.pem'); * $business->setClientKey('/your/path/to/apiclient_key.pem'); */ $business = new Business(); $business->appid(APPID); $business->appsecret(APPSECRET); $business->mch_id(MCHID); $business->mch_key(MCHKEY); /** * 第 2 步:定义订单 */ $order = new Order(); $order->body('iphone 6 plus'); $order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999)); $order->total_fee('1'); $order->openid($_SESSION['openid']); $order->notify_url(NOTIFY_URL); /** * 第 3 步:统一下单 */ $unifiedorder = new Unifiedorder(); $unifiedorder->setBusiness($business); $unifiedorder->setOrder($order); /** * 第 4 步:生成支付配置文件 */ try {
/** * 第 1 步:定义商户 * 设置商户证书路径请使用 setClientCert/setClientKey * $business->setClientCert('/your/path/to/apiclient_cert.pem'); * $business->setClientKey('/your/path/to/apiclient_key.pem'); */ $business = new Business(); $business->appid(APPID); $business->appsecret(APPSECRET); $business->mch_id(MCHID); $business->mch_key(MCHKEY); // print_r($business->getParams()); /** * 第 2 步:定义订单 */ $order = new Order(); $order->body('iphone 6 plus'); $order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999)); $order->total_fee('1'); // $order->openid($_SESSION['openid']); $order->openid('oWY-5jjLjo7pYUK86JPpwvcnF2Js'); $order->notify_url(Util::currentUrl()); // print_r($order->getParams()); /** * 第 3 步:统一下单 */ $unifiedorder = new Unifiedorder(); $unifiedorder->setBusiness($business); $unifiedorder->setOrder($order); /** * 第 4 步:生成支付配置文件
*/ $businessA = new Business(); $businessA->appid(APPID); $businessA->appsecret(APPSECRET); $businessA->mch_id(MCHID); $businessA->mch_key(MCHKEY); // 可以配置多个商户 // $businessB = new Business(); // $businessB->appid(APPID); // $businessB->appsecret(APPSECRET); // $businessB->mch_id(MCHID); // $businessB->mch_key(MCHKEY); /** * 第 2 步:定义订单(可链式调用) */ $order = new Order(); $order->body('iphone 6 plus'); $order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999)); $order->total_fee('1'); $order->trade_type('NATIVE'); $order->notify_url('Your notify url'); /** * 第 3 步:统一下单 */ $unifiedorder = new Unifiedorder($businessA, $order); $response = $unifiedorder->getResponse(); if (!isset($response['code_url'])) { exit($e->getMessage()); } /** * 生成支付二维码
} /** * 第 1 步:定义商户 * 设置商户证书路径请使用 setClientCert/setClientKey * $business->setClientCert('/your/path/to/apiclient_cert.pem'); * $business->setClientKey('/your/path/to/apiclient_key.pem'); */ $business = new Business(); $business->appid(APPID); $business->appsecret(APPSECRET); $business->mch_id(MCHID); $business->mch_key(MCHKEY); /** * 第 2 步:定义订单 */ $order = new Order(); $order->body('iphone 6 plus'); $order->out_trade_no(date('Y-m-dHis') . mt_rand(10000, 99999)); $order->total_fee('1'); $order->openid($_SESSION['openid']); $order->notify_url(NOTIFY_URL); /** * 第 3 步:统一下单 */ $unifiedorder = new Unifiedorder($business, $order); /** * 第 4 步:生成支付配置文件 */ try { $payment = new Payment($unifiedorder); $config = $payment->getConfig();