public static IContent BuildPrepayContent(string prepay_id) { string package = "prepay_id=" + prepay_id; string timeStamp = ((int)(DateTime.Now - EPOCH).TotalSeconds).ToString(); JObj jo = new JObj { new JMbr("appId", appid), new JMbr("nonceStr", noncestr), new JMbr("package", package), new JMbr("signType", "MD5"), new JMbr("timeStamp", timeStamp), }; jo.Add("paySign", Sign(jo, "paySign")); return(jo.Dump()); }
JObj ParseObj(ref int pos) { JObj jo = new JObj(); int p = pos; for (;;) { for (;;) { if (p >= length - 1) { throw ParseEx; } int b = this[++p]; if (b == ' ' || b == '\t' || b == '\n' || b == '\r') { continue; } if (b == '"') { break; // meet first quote } if (b == '}') // close early empty { pos = p; return(jo); } throw ParseEx; } str.Clear(); // parse name for (;;) { if (p >= length - 1) { throw ParseEx; } int b = this[++p]; if (b == '"') { break; // meet second quote } str.Add((char)b); } for (;;) // till a colon { if (p >= length - 1) { throw ParseEx; } int b = this[++p]; if (b == ' ' || b == '\t' || b == '\n' || b == '\r') { continue; } if (b == ':') { break; } throw ParseEx; } string name = str.ToString(); // parse the value part for (;;) { if (p >= length - 1) { throw ParseEx; } int b = this[++p]; if (b == ' ' || b == '\t' || b == '\n' || b == '\r') { continue; // skip ws } if (b == '{') { JObj v = ParseObj(ref p); jo.Add(name, v); } else if (b == '[') { JArr v = ParseArr(ref p); jo.Add(name, v); } else if (b == '"') { string v = ParseString(ref p); jo.Add(name, v); } else if (b == 'n') { if (ParseNull(ref p)) { jo.AddNull(name); } } else if (b == 't' || b == 'f') { bool v = ParseBool(ref p, b); jo.Add(name, v); } else if (b == '-' || b >= '0' && b <= '9') { JNumber v = ParseNumber(ref p, b); jo.Add(name, v); } else if (b == '&') // bytes extension { byte[] v = ParseBytes(p); jo.Add(name, v); } else { throw ParseEx; } break; } // comma or end for (;;) { if (p >= length - 1) { throw ParseEx; } int b = this[++p]; if (b == ' ' || b == '\t' || b == '\n' || b == '\r') { continue; } if (b == ',') { break; } if (b == '}') // close normal { pos = p; return(jo); } throw ParseEx; } } }