ps:接着之前的完成了微信授权获取用户的基础信息外
微信支付也需要快速完成,支付的确很多坑,大多数是不认真阅读开发文档导致
stemp1 :发起预支付api
此处遇到的坑是,由于需求中的信息,例如公众号下对应一个商户号,但是需求文档中给的商户号是错误的,不是这个公众号对应下的商户号,
直接被返回 公众号与商户号不一致!!!,此时经历了寻找好几个部门的人,终于找到了对应的商户号!然而已经懵逼了好久….
#region 扫码进行打赏操作
/// <summary>
/// HttpPost
/// api/Appraise/ScanToAward
/// 打赏
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionName("ScanToAward")]
public IHttpActionResult ScanToAward(ScanToAwardModel model)
{
string scan_notify_url = "你的回调地址";
try
{
if (model == null)
{
throw new CustomException("操作失败,无效参数");
}
if (string.IsNullOrEmpty(model.totle_fee))
{
throw new CustomException("操作失败,无效打赏金额");
}
//if (string.IsNullOrEmpty(model.UserId))
//{
// throw new CustomException("操作失败,无效顾客信息");
//}
string prepay_id = "";
int crid = model.CID.ToIntForPage();
int uid = model.UserId.ToIntForPage();
decimal totalfee = model.totle_fee.ToDecimal();
DateTime now = DateTime.Now;
//数据库操作,省略*******
weixin_payment payment = new weixin_payment
{
appid = "",
mchid = "",
CID = cid,
body = "扫码打赏",
Name = cr.Name,
itime = now,
openid = userUserID.openid,
out_trade_no = "wx" + DateTime.Now.ToString("yyyyMMddHHmmssfff"),
scene_info = "扫码打赏",
SName = SpName,
UserId = uid,
notify_url = scan_notify_url,
total_fee = totalfee,
};
dbo.weixin_payment.Add(payment);
int r = dbo.SaveChanges();
if (r > 0)
{
string temp = WechatService.WechatPrePayScan(payment.body, payment, "JSAPI", "127.0.0.1", out prepay_id);
return Json(Success(temp.Replace("\\", "")));
}
else
{
return Json(getException("打赏失败"));
}
}
catch (CustomException ce)
{
// 数据库操作
return Json(getException(ce.Message));
}
catch (Exception ex)
{
// 数据库操作
return Json(getException(ex));
}
}
#endregion
stemp2 预支付主要函数,主要是进行签名,参数一定到正确,如下:
/// <summary>
/// 执行微信预支付
/// </summary>
/// <param name="gooddesc">产品描述</param>
/// <param name="orderno">订单编号</param>
/// <returns></returns>