public function getAppPaymentParameters($order) { /* $order =null; $order = $this->queryOrder($out_trade_no); // print json_encode($order) .PHP_EOL; if ($order) { $input = new \WxPayReverse(); $input->SetOut_trade_no($out_trade_no); $result = \WxPayApi::reverse($input); print('reserve:'.json_encode($result)) .PHP_EOL; // $input = new \WxPayCloseOrder(); // $input->SetOut_trade_no($out_trade_no); // $result = \WxPayApi::closeOrder($input); // print('close:'.json_encode($result)) .PHP_EOL; } */ $wxPayConfig = $this->wxPayApi->getWxPayConfig(); // print( json_encode($order ) ) .PHP_EOL; $prepay_id = $order['prepay_id']; $response = array('appid' => $wxPayConfig['APPID'], 'partnerid' => $wxPayConfig['MCHID'], 'prepayid' => $prepay_id, 'package' => 'Sign=WXPay', 'noncestr' => \WxPayApi::getNonceStr(), 'timestamp' => time()); $response['sign'] = $this->calculateSign($response, $wxPayConfig['KEY']); // send it to APP return $response; }
/** * * 获取jsapi支付的参数 * @param array $UnifiedOrderResult 统一支付接口返回的数据 * @throws WxPayException * * @return json数据,可直接填入js函数作为参数 */ public function GetJsApiParameters($UnifiedOrderResult) { if (!array_key_exists("appid", $UnifiedOrderResult) || !array_key_exists("prepay_id", $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == "") { throw new WxPayException("参数错误"); } $jsapi = new WxPayJsApiPay(); $jsapi->SetAppid($UnifiedOrderResult["appid"]); $timeStamp = time(); $jsapi->SetTimeStamp("{$timeStamp}"); $jsapi->SetNonceStr(WxPayApi::getNonceStr()); $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']); $jsapi->SetSignType("MD5"); $jsapi->SetPaySign($jsapi->MakeSign()); $parameters = json_encode($jsapi->GetValues()); return $parameters; }
/** * * 获取jsapi支付的参数 * @param array $UnifiedOrderResult 统一支付接口返回的数据 * @throws WxPayException * * @return json数据,可直接填入js函数作为参数 */ public function GetJsApiParameters($UnifiedOrderResult) { if (!array_key_exists("appid", $UnifiedOrderResult) || !array_key_exists("prepay_id", $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == "") { // throw new WxPayException("参数错误"); Yii::log('WxJsPayHelper 71line', CLogger::LEVEL_ERROR, 'WxJsPayHelper'); Yii::app()->request->redirect(Assist::getDefaultURL()); } $jsapi = new WxPayJsApiPay(); $jsapi->SetAppid($UnifiedOrderResult["appid"]); $timeStamp = time(); $jsapi->SetTimeStamp($timeStamp); $jsapi->SetNonceStr(WxPayApi::getNonceStr()); $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']); $jsapi->SetSignType("MD5"); $jsapi->SetPaySign($jsapi->MakeSign()); $parameters = json_encode($jsapi->GetValues()); return $parameters; }
public function NotifyProcess($data) { if (!array_key_exists("openid", $data) || !array_key_exists("product_id", $data)) { $this->msg = "回调数据异常"; return false; } $openid = $data["openid"]; $product_id = $data["product_id"]; //统一下单 $result = $this->unifiedorder($openid, $product_id, $data); if (!array_key_exists("appid", $result) || !array_key_exists("mch_id", $result) || !array_key_exists("prepay_id", $result)) { $this->msg = "统一下单失败"; return false; } $this->SetData("appid", $result["appid"]); $this->SetData("mch_id", $result["mch_id"]); $this->SetData("nonce_str", WxPayApi::getNonceStr()); $this->SetData("prepay_id", $result["prepay_id"]); $this->SetData("result_code", "SUCCESS"); $this->SetData("err_code_des", "OK"); return true; }
public function pay_get() { $order = I('get.order', ''); $m = M('orders'); // $map['from_member_id'] = $this->uid; $map['order_number'] = $order; // $map['status'] = 0; $info = $m->where($map)->find(); if (empty($info)) { //未支付订单不存在 $this->error(5015); } $total = $info['total'] * 100; $describe = 'testname'; require_once APP_PATH . "SDK/Payment/wechat/lib/WxPay.Api.php"; $input = new \WxPayUnifiedOrder(); //设置公众账号ID $input->SetAppid(\WxPayConfig::APPID); //设置商户号 $input->SetMch_id(\WxPayConfig::MCHID); //设置随机字符串 $input->SetNonce_str(\WxPayApi::getNonceStr()); //设置商品描述 $input->SetBody($describe); //设置商户订单号 $input->SetOut_trade_no($info['order_number']); //设置总金额 $input->SetTotal_fee($total); //设置终端IP $input->SetSpbill_create_ip(get_client_ip()); //设置通知地址 $input->SetNotify_url(U('Wxpay/callback@api')); //设置交易类型 $input->SetTrade_type('APP'); $order = \WxPayApi::unifiedOrder($input); $this->success($order); }
public function wxpay_app() { $period_id = Input::get('period_id'); $period = Period::find($period_id); // 判断时间段有效性 if (!isset($period)) { return Response::json(array('error_code' => 2, 'message' => '无该时间段,请重新选择')); } if ($period->current >= $period->total) { return Response::json(array('error_code' => 3, 'message' => '已满人,请重新选择')); } $schedule = $period->schedule; $doctor = $schedule->doctor; $user_id = Session::get('user.id'); // 选择指定挂号账户 if (Input::has('account_id')) { $account_id = Input::get('account_id'); $account = RegisterAccount::find($account_id); if (!isset($account)) { return Response::json(array('error_code' => 4, 'message' => '不存在该挂号账户')); } if ($account->user_id != $user_id) { return Response::json(array('error_code' => 5, 'message' => '无效账户')); } } else { $account = RegisterAccount::where('user_id', $user_id)->first(); if (!isset($account)) { return Response::json(array('error_code' => 6, 'message' => '请先申请挂号账户')); } $account_id = $account->id; } $user_id = Session::get('user.id'); $attach = array('period_id' => (int) Input::get('period_id'), 'account_id' => $account_id); try { $period = Period::find(Input::get('period_id')); $schedule = $period->schedule; $doctor = $schedule->doctor; $order = $this->create_order($user_id, 'APP', json_encode($attach), (int) ($doctor->register_fee * 100)); $para = array('appid' => $order['appid'], 'partnerid' => WxPayConfig::MCHID, 'prepayid' => $order['prepay_id'], 'package' => 'Sign=WXPay', 'noncestr' => WxPayApi::getNonceStr(), 'timestamp' => time()); $wxpay_result = new WxPayResults(); $wxpay_result->FromArray($para); $wxpay_result->SetSign(); $package = $wxpay_result->GetValues(); } catch (Exception $e) { return Response::json(array('error_code' => 1, 'message' => $e->getMessage())); } return Response::json(array('error_code' => 0, 'package' => $package)); }
function joinwxinfo($body_arr) { $resp = array(); $order_no = $body_arr['order_no']; $randnum = rand(1000, 9999); //产生一个4位随机数 $out_trade_no = $order_no; //. '-' . $randnum; //记录订单号+_+随机数 // $arr['device_info'] = isset($body_arr['client_ip'])?$body_arr['client_ip']:''; //客户端地址 $input = new WxPayUnifiedOrder(); $input->SetBody($out_trade_no); $input->SetOut_trade_no($out_trade_no); $input->SetTotal_fee(getfee($body_arr)); //这里是微信,默认单位:分 $time = time(); $input->SetTime_start(date("YmdHis"), $time); $input->SetTime_expire(date("YmdHis", $time + 600)); $input->SetNotify_url(_WXNOTIFYURL_ . 'pay/mobilepay/wxpay/interface/appnotify.php'); $input->SetTrade_type("APP"); // $WxPayUnifiedOrder->SetAttach("test"); // $input->SetGoods_tag("test"); // $input->SetProduct_id("123456789"); $retarr = WxPayApi::unifiedOrder($input); //返回数据解析为数组了 if ($retarr['return_code'] == 'SUCCESS') { //成功 $nostr = WxPayApi::getNonceStr(); $resp['wx_app_id'] = $retarr['appid']; $resp['wx_partner_id'] = $retarr['mch_id']; $resp['wx_nonce'] = $nostr; //$retarr['nonce_str']; $resp['wx_timestamp'] = $time; //date("YmdHis"); $retinput = new WxPayReplyData(); if ($retarr['result_code'] == 'SUCCESS') { $resp['wx_prepay_id'] = $retarr['prepay_id']; $retinput->SetappId(WxPayConfig::APPID); //公众账号ID $retinput->SetnonceStr($nostr); //随机字符串 $retinput->Setpackage('Sign=WXPay'); $retinput->SetpartnerId($retarr['mch_id']); $retinput->SetprepayId($retarr['prepay_id']); $retinput->SettimeStamp($time); // $resp['wx_sign'] = $retinput->MakeSignSpecil(); } $resp['wx_package'] = 'Sign=WXPay'; //固定值 } else { $resp = $retarr; $resp['status'] = 1046; $resp['desc'] = '失败'; } return $resp; }
/** * * 按类型获取支付凭证 * @param data */ public static function getPayConfig($data) { $input = self::getUnifiedOrder($data); $config = WxPayApi::unifiedOrder($input); if ($config['return_code'] == 'FAIL') { throw new WxPayException($config['return_msg'], 1); } if ($data['trade_type'] = 'JSAPI') { $jsapi = new WxPayJsApiPay(); $jsapi->SetAppid($config["appid"]); $jsapi->SetTimeStamp(strtotime($data['time_start'])); $jsapi->SetNonceStr(WxPayApi::getNonceStr()); $jsapi->SetPackage("prepay_id=" . $config['prepay_id']); $jsapi->SetSignType("MD5"); $jsapi->SetPaySign($jsapi->MakeSign()); $parameters = json_encode($jsapi->GetValues()); return $parameters; } else { if ($data['trade_type'] = 'APP') { // TODO HBuilder // // 参与签名的字段名为appId,partnerId,prepayId,nonceStr,timeStamp,package。注意:package的值格式为Sign=WXPay // $time_stamp = time(); // $pack = 'Sign=WXPay'; // //输出参数列表 // $prePayParams =array(); // $prePayParams['appid'] =$config['appid']; // $prePayParams['partnerid'] =$config['mch_id']; // $prePayParams['prepayid'] =$config['prepay_id']; // $prePayParams['noncestr'] =$config['nonce_str']; // $prePayParams['package'] =$pack; // $prePayParams['timestamp'] =$time_stamp; // $prePayParams['sign'] =$config['sign']; // return $prePayParams; } } return $config; }