Пример #1
0
        public void TestSend()
        {
            AlipayOpenAppMiniTemplatemessageSendResponse response = Factory.Marketing.TemplateMessage().Send(
                "2088102122458832",
                "2017010100000000580012345678",
                "MDI4YzIxMDE2M2I5YTQzYjUxNWE4MjA4NmU1MTIyYmM=",
                "page/component/index",
                "{\"keyword1\": {\"value\" : \"12:00\"},\"keyword2\": {\"value\" : \"20180808\"},\"keyword3\": {\"value\" : \"支付宝\"}}");

            Assert.AreEqual(response.Code, "40004");
            Assert.AreEqual(response.Msg, "Business Failed");
            Assert.AreEqual(response.SubCode, "USER_TEMPLATE_ILLEGAL");
            Assert.AreEqual(response.SubMsg, "模板非法");
            Assert.NotNull(response.HttpBody);
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                //PayLogHelper.WritePayLog(Request.Form.ToString());
                //Notify aliNotify = new Notify();
                Notify aliNotify    = new Notify(AliPayConfig.charset, AliPayConfig.sign_type, AliPayConfig.pid, AliPayConfig.mapiUrl, AliPayConfig.alipay_miniapp_public_key);
                bool   verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

                //商户订单号
                string     out_trade_no = Request.Form["out_trade_no"];
                Data_Order order        = null;

                if (verifyResult && CheckParams(out order))//验证成功
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                    //支付宝交易号
                    string trade_no = Request.Form["trade_no"];

                    //交易状态
                    //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。
                    string trade_status = Request.Form["trade_status"];

                    //交易状态
                    if (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED")
                    {
                        try
                        {
                            if (MPOrderBusiness.UpdateOrderForPaySuccess(out_trade_no, trade_no))
                            {
                                LogHelper.SaveLog(TxtLogType.AliPay, TxtLogContentType.Debug, TxtLogFileType.Day, "应用:莘拍档 订单号:" + out_trade_no + " 支付成功!");

                                //支付宝买家用户id
                                string buyer_id = Request.Form["buyer_id"];
                                //支付时间
                                string gmt_payment = HttpUtility.UrlDecode(Request.Form["gmt_payment"]);

                                string aliId = string.Empty;
                                string msg   = string.Empty;
                                if (!MobileTokenBusiness.GetAliId(order.Mobile, out aliId, out msg))
                                {
                                    bool ret = MobileTokenBusiness.UpdateAliBuyerId(order.Mobile, buyer_id);
                                }

                                IAopClient client = new DefaultAopClient(AliPayConfig.serverUrl, AliPayConfig.miniAppId, AliPayConfig.merchant_miniapp_private_key, "json", "1.0", "RSA2", AliPayConfig.alipay_miniapp_public_key, AliPayConfig.charset, false);
                                AlipayOpenAppMiniTemplatemessageSendRequest request = new AlipayOpenAppMiniTemplatemessageSendRequest();
                                request.BizContent = "{" +
                                                     "\"to_user_id\":\"" + buyer_id + "\"," +
                                                     "\"form_id\":\"" + trade_no + "\"," +
                                                     "\"user_template_id\":\"" + AliPayConfig.MiniAppTemplateId + "\"," +
                                                     "\"page\":\"pages/login/login\"," +
                                                     "\"data\":\"{\\\"keyword1\\\":{\\\"value\\\":\\\"" + out_trade_no + "\\\"},\\\"keyword2\\\":{\\\"value\\\":\\\"" + order.Descript + "\\\"},\\\"keyword3\\\":{\\\"value\\\":\\\"" + order.Price.ToString("0.00") + "\\\"},\\\"keyword4\\\":{\\\"value\\\":\\\"" + order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") + "\\\"},\\\"keyword5\\\":{\\\"value\\\":\\\"" + gmt_payment + "\\\"}}\"" +
                                                     "}";
                                AlipayOpenAppMiniTemplatemessageSendResponse response = client.Execute(request);
                            }
                            else
                            {
                                LogHelper.SaveLog(TxtLogType.AliPay, TxtLogContentType.Debug, TxtLogFileType.Day, "应用:莘拍档 订单号:" + out_trade_no + " 已支付订单更新失败!!!");
                            }
                        }
                        catch (Exception ex)
                        {
                            //PayLogHelper.WriteError(ex);
                            LogHelper.SaveLog(TxtLogType.AliPay, ex.InnerException != null ? ex.InnerException.Message : ex.Message);
                        }

                        //判断是否在商户网站中已经做过了这次通知返回的处理
                        //如果没有做过处理,那么执行商户的业务程序
                        //如果有做过处理,那么不执行商户的业务程序
                        Response.Write("success");  //请不要修改或删除
                    }
                    else
                    {
                        Response.Write("fail");
                    }

                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    LogHelper.SaveLog(TxtLogType.AliPay, TxtLogContentType.Debug, TxtLogFileType.Day, "应用:莘拍档 订单号:" + out_trade_no + " 警告:支付回调验证失败!!!");
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }