Exemplo n.º 1
0
 /**
  * 
  * 获取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;
 }
Exemplo n.º 2
0
 public function NotifyProcess($data, &$msg)
 {
     //echo "处理回调";
     Log::DEBUG("call back:" . json_encode($data));
     if (!array_key_exists("openid", $data) || !array_key_exists("product_id", $data)) {
         $msg = "回调数据异常";
         return false;
     }
     $openid = $data["openid"];
     $product_id = $data["product_id"];
     //统一下单
     $result = $this->unifiedorder($openid, $product_id);
     if (!array_key_exists("appid", $result) || !array_key_exists("mch_id", $result) || !array_key_exists("prepay_id", $result)) {
         $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;
 }